<?php
class GouwuAction extends CommonAction{

    function _initialize() {
        $this->stopService();

		//$this->_inject_check(0); //调用过滤函数
		//$this->_checkUser();
		//$this->check_us_gq();
		header("Content-Type:text/html; charset=utf-8");
	}

    //二级验证
    public function Cody(){
        //$this->_checkUser();
        $UrlID = (int) $_GET['c_id'];
        if (empty($UrlID)){
            $this->error('二级密码错误!');
            exit;
        }
		if(!empty($_SESSION['user_pwd2'])){
			$url = __URL__."/codys/Urlsz/$UrlID";
			$this->_boxx($url);
			exit;
		}
		$cody   =  M ('cody');
		$list   =  $cody->where("c_id=$UrlID")->field('c_id')->find();
		if (!empty($list)){
		    $this->assign('vo',$list);
			$this->display('Public:cody');
		    exit;
		}else{
		    $this->error('二级密码错误!');
		    exit;
		}
    }
	//二级验证后调转页面
	public function Codys() {
		$Urlsz = $_POST['Urlsz'];
		if(empty($_SESSION['user_pwd2'])){
			$pass = $_POST['oldpassword'];
			$fck = M('fck');
			if (!$fck->autoCheckToken($_POST)) {
				$this->error('页面过期请刷新页面!');
				exit ();
			}
			if (empty ($pass)) {
				$this->error('二级密码错误!');
				exit ();
			}
			$where = array ();
			$where['id'] = $_SESSION[C('USER_AUTH_KEY')];
            $where['passopen'] = md5($pass);

            $list = $fck->where($where)->field('id')->find();
			if ($list == false) {
				$this->error('二级密码错误!');
				exit ();
			}
			$_SESSION['user_pwd2'] = 1;
		}else{
			$Urlsz = $_GET['Urlsz'];
		}
		switch ($Urlsz) {
			case 1;
				$_SESSION['UrlszUserpass'] = 'MyssGuanChanPin';
				$bUrl = __URL__ . '/pro_index';
				$this->_boxx($bUrl);
				break;
			case 2;
				$_SESSION['UrlszUserpass'] = 'MyssWuliuList';
				$bUrl = __URL__ . '/adminLogistics';
				$this->_boxx($bUrl);
				break;
			case 3;
				$_SESSION['UrlszUserpass'] = 'ACmilan';
				$bUrl = __URL__ . '/Buycp';
				$this->_boxx($bUrl);
				break;
			case 4;
				$_SESSION['UrlszUserpass'] = 'manlian';//求购股票
				$bUrl = __URL__ . '/BuycpInfo';
				$this->_boxx($bUrl);
				break;
        case 5;
        $_SESSION['UrlszUserpass'] = 'MyssWuliuList';//求购股票
        $bUrl = __URL__ . '/userLogistics';
        $this->_boxx($bUrl);
        break;
			default;
                $bUrl = __APP__;
                $this->_box(1,'二级密码已验证，无需重复操作！',$bUrl,1);
				break;
		}
	}

  public function address(){
    $this->display('querendingdan');
  }

public function order(){
    $oid =md5($_POST['oid']);
    $id = $_SESSION[C('USER_AUTH_KEY')]; 
    $pwass = M('fck')->where('id='.$id)->field('passopen')->find();
    if($oid==$pwass['passopen']){
      echo '1';die;
    }else{
      echo '2';die;
    }
  }
	public function gouwuAC(){
		//处理提交按钮
		$action = $_POST['action'];
		$PTid = $_SESSION[C('USER_AUTH_KEY')];
		$nums = $_POST['nums'];
		$cid=$_POST['id'];
        if ($PTid == null){
            $bUrl = __APP__.'/Public/login';
            $this->_box(1,'请先登录！',$bUrl,1);
            exit;
        }
		switch ($action){
			case '加入购物车';
				$this->addcat($PTid,$nums,$cid);
				break;
			case '立即购买';
				$this->ShoppingListAddAC(1,$nums,$cid,0);
				break;	

		}
	}

    /**
     * 填写收货信息，等待生成订单时将地址直接写入购物表
     */
	public function logisticsInfo(){
        $oid = trim(I('oid'));
        $this->assign('oid',$oid);


        $order = M('collection')->where('id='.$oid)->find();
        $info  = M('product')->where('id='.$order['pid'])->find();
        $this->assign('order',$order);
        $this->assign('info',$info);

        unset($order,$info);
        $this->display();
    }
    public function logisticsInfo1(){
        $oid = trim(I('oid'));
        $this->assign('oid',$oid);


        $order = M('address')->where('id='.$oid)->find();
        $this->assign('order',$order);

        unset($order,$info);
        $this->display('dizhisave');
    }
  
    /**
     * 保存物流信息
     */
    public function saveLogisticsInfo(){
	    $us_name = trim(I('us_name'));
	    $us_address = trim(I('us_address'));
	    $us_tel = trim(I('us_tel'));
	    if (empty($us_name)){
	        $this->error('请填写收货姓名！');
        }
        if (empty($us_address)){
	        $this->error('请填写收货地址！');
        }
        if (empty($us_tel)){
	        $this->error('请填写收货电话！');
        }
        $oid = I('oid');
        $data = array('us_name'=>$us_name,'us_address'=>$us_address,'us_tel'=>$us_tel);
        $res = M('collection')->where("id={$oid}")->setField($data);
        if ($res){
            $bUrl = __URL__.'/Shopcar';
            $this->_box(1,'保存成功！',$bUrl,1);
            exit;
        }else{
            $this->error('保存失败！');
        }
        unset($data);
    }
    public function moreng(){
      $id = I('id');
      $data['moren'] = 0;
      $sele = M('address')->where('moren=1')->save($data);
        $dat['moren'] = 1;
        $sesle = M('address')->where('id='.$id)->save($dat);
        if($sesle){
          echo '设为默认地址';die;
        }
      
    }

    //地址管理
    public function dizhi(){
      $id = $_SESSION[C('USER_AUTH_KEY')];
        $order = M('address')->where('uid='.$id)->select();
        
        $this->assign('order',$order);

        unset($order,$info);
        $this->display();
    }
    //添加地址
    public function dizhiadds(){
      $id = $_SESSION[C('USER_AUTH_KEY')];
      $data['uid'] = $id;
      $data['name'] = $_POST['us_name'];
      $data['address'] = $_POST['us_address'];
      $data['tel'] = $_POST['us_tel'];
      if(empty($data['name'])){
        $this->error('请填写收货人！');
      }
      if(empty($data['address'])){
        $this->error('请填写收货地址！');
      }
      if(empty($data['tel'])){
        $this->error('请填写电话号码！');
      }
      $order = M('address')->add($data);
      if($order){
          $bUrl = __URL__.'/dizhi';
            $this->_box(1,'添加成功！',$bUrl,1);
            exit;
      }else{
        $this->error('添加失败！');
      }

    }
    //修改地址
    public function savedizhi(){
      $id = $_SESSION[C('USER_AUTH_KEY')];
      $data['uid'] = $id;
      $data['name'] = $_POST['us_name'];
      $data['address'] = $_POST['us_address'];
      $data['tel'] = $_POST['us_tel'];
      $order = M('address')->where('id = '.$_POST['oid'])->save($data);
      if($order){
          $bUrl = __URL__.'/dizhi';
            $this->_box(1,'修改成功！',$bUrl,1);
            exit;
      }else{
        $this->error('修改失败！');
      }
    }
    //删除地址
    public function dizhiselect(){
      $id = I('oid');
      $order = M('address')->where('id='.$id)->delete();
      if($order){
          $bUrl = __URL__.'/dizhi';
            $this->_box(1,'删除成功！',$bUrl,1);
            exit;
      }else{
        $this->error('删除失败！');
      }  

        $this->display();
    }

    public function zhifuAC(){
		//处理提交按钮
		$action = $_POST['action'];
		$PTid = $_SESSION[C('USER_AUTH_KEY')];
		$nums = $_POST['money'];
		$cid=$_POST['cid'];

		switch ($action){
			case '1';
				$this->addcat($action,$nums,$cid);
				break;
			case '2';
				$this->ShopingSave($action,$nums,$cid);
				break;
			case '3';
				$this->ShopingSave($action,$nums,$cid);
				break;
			case '4';
				$this->ShopingSave($action,$nums,$cid);
				break;

		}
	}	
public function addcat($pid,$nums,$cid){
        if ($nums==0 ||$nums == null){
            $this->error("数量不能为0");
        }

        $collection = M('collection');

		$data['uid'] = $_SESSION[C('USER_AUTH_KEY')];
		$data['pid'] = $cid;
		$data['num'] = $nums;
		$data['time'] = time();
		$form_rs = $collection->add($data);
		
		if($form_rs){
			$bUrl = __URL__.'/Buycp';
		    $this->_box(1,'加入成功！',$bUrl,1);
		    exit;
		}
		else{
			$this->error("操作失败");
			exit;
		}

}

public function gouwajax(){
}
public function yanzheng() {




        $code=$_GET['code'];
      

        $url="https://api.weixin.qq.com/sns/oauth2/access_token?";
        $post_data="appid=wxdfc6fec1902c9870&secret=2f6643d8d42a16646da60953e61f2af2&code=".$code."&grant_type=authorization_code";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false );
       
        $result = curl_exec($ch);
         if(curl_errno($ch)){
            // 显示报错信息；终止继续执行
            die(curl_error($ch));
        }
        curl_close($ch);
         $result2 = json_decode($result,true);

        $dd=$result2['access_token'];
        $pid=$result2['openid'];
        $_SESSION['login_count']        =   $pid;
        $_SESSION['login_isAgent']      =   $dd;
    
   
  
      
      
     
        $url1="https://api.weixin.qq.com/sns/userinfo?";
        $post_data1="access_token=".$dd."&openid=".$pid."&lang=zh_CN";
        $ch1 = curl_init();
        curl_setopt($ch1, CURLOPT_POST, 1);
        curl_setopt($ch1, CURLOPT_HEADER, 0);
        curl_setopt($ch1, CURLOPT_URL, $url1);
        curl_setopt($ch1, CURLOPT_POSTFIELDS, $post_data1);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch1, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt ($ch1, CURLOPT_SSL_VERIFYPEER, false );
       
        $result1 = curl_exec($ch1);
       $data = json_decode($result1,true);

      $fck=M('fck');
      $time=time();
     

      $a=$fck->where("user_id='".$pid."'")->find();
      if(!$a){

       // $aid=$_SESSION['loginUseracc'];
       

          $tt=array();
          $tt['user_id']=$pid;
          $tt['nickname']=$data['nickname'];
          $tt['get_ceng']=$data['sex'];
          $tt['us_img']=$data['headimgurl'];
          $tt['u_level']=0;
          $tt['pdt']    =$time;
          $tt['new_login_time']=$time;
          $rs=$fck->add($tt);
          if($rs){
            $aa=$fck->where("user_id='".$pid."'")->find();
            $_SESSION[C('USER_AUTH_KEY')]    =   $aa['id']; 
          }
        }
        
    else{
       $fck->execute("update __TABLE__ set nickname='".$data['nickname']."',us_img='".$data['headimgurl']."',get_ceng=".$data['sex'].",new_login_time=".$time." where user_id='".$pid."'");
      
       $_SESSION[C('USER_AUTH_KEY')]    =   $a['id'];
      
        
    }
    

   $this->Buycp();

    }
public function yanzheng2() {




        $code=$_GET['code'];
      

        $url="https://api.weixin.qq.com/sns/oauth2/access_token?";
        $post_data="appid=wxdfc6fec1902c9870&secret=2f6643d8d42a16646da60953e61f2af2&code=".$code."&grant_type=authorization_code";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false );
       
        $result = curl_exec($ch);
         if(curl_errno($ch)){
            // 显示报错信息；终止继续执行
            die(curl_error($ch));
        }
        curl_close($ch);
         $result2 = json_decode($result,true);

        $dd=$result2['access_token'];
        $pid=$result2['openid'];
        $_SESSION['login_count']        =   $pid;
        $_SESSION['login_isAgent']      =   $dd;
    
   
  
      
      
     
        $url1="https://api.weixin.qq.com/sns/userinfo?";
        $post_data1="access_token=".$dd."&openid=".$pid."&lang=zh_CN";
        $ch1 = curl_init();
        curl_setopt($ch1, CURLOPT_POST, 1);
        curl_setopt($ch1, CURLOPT_HEADER, 0);
        curl_setopt($ch1, CURLOPT_URL, $url1);
        curl_setopt($ch1, CURLOPT_POSTFIELDS, $post_data1);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch1, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt ($ch1, CURLOPT_SSL_VERIFYPEER, false );
       
        $result1 = curl_exec($ch1);
       $data = json_decode($result1,true);

      $fck=M('fck');
      $time=time();
     

      $a=$fck->where("user_id='".$pid."'")->find();
      if(!$a){

       // $aid=$_SESSION['loginUseracc'];
       

          $tt=array();
          $tt['user_id']=$pid;
          $tt['nickname']=$data['nickname'];
          $tt['get_ceng']=$data['sex'];
          $tt['us_img']=$data['headimgurl'];
          $tt['u_level']=0;
          $tt['pdt']    =$time;
          $tt['new_login_time']=$time;
          $rs=$fck->add($tt);
          if($rs){
            $aa=$fck->where("user_id='".$pid."'")->find();
            $_SESSION[C('USER_AUTH_KEY')]    =   $aa['id']; 
          }
        }
        
    else{
       $fck->execute("update __TABLE__ set nickname='".$data['nickname']."',us_img='".$data['headimgurl']."',get_ceng=".$data['sex'].",new_login_time=".$time." where user_id='".$pid."'");
      
       $_SESSION[C('USER_AUTH_KEY')]    =   $a['id'];
      
        
    }

         $this->jinguo();

    }
 public function rugu(){
 	    $product=M('product');
		$prs = $product->where('id=2')->field('*')->find();
		$this->assign('prs',$prs);
        $time=time();
		$nowdate2 = strtotime(date('Y-m-d'))+23*3600;
		$nowdate = strtotime(date('Y-m-d'))+22*3600;
		if($time>=$nowdate && $time<=$nowdate2){
          $shul=1;

		}
		else{
			$shul=0;
		}
        $this->assign('shul',$shul);
		
		$this->display();

	}   
public function rengengAC(){
		//处理提交按钮
		$fck=M('fck');
		$fee=M('fee')->field('s8')->find();
		$s5=explode("|",$fee['s8']);
		$id=$_SESSION[C('USER_AUTH_KEY')];
		$nums = $_POST['nums'];
		$cid=$_POST['id'];
		$time=time();
		$nowdate2 = strtotime(date('Y-m-d'))+23*3600;
		$nowdate = strtotime(date('Y-m-d'))+22*3600;

		if($time>=$nowdate && $time<=$nowdate2){
          $shul=$s8[1];

		}
		else{
			$shul=$s8[0];
		}
        $a=$fck->where('id='.$id)->field('u_level')->find();
      // $u_level=$a['u_level'];
     // if($u_level==0){
      //	$this->error('您还没有开通成为会员，不能够购买果树！请先去注册');
      //	exit;
    //  }


       if($nums>$shul){
          $this->error("您最多只能购买".$shul."股的股权！");
          exit;
       }
		else{
           $this->ShoppingListAddAC(2,$nums,$cid,0);
		}
		
		
	}
public function pai(){
        $cid=$_GET['id'];
        $this->ShoppingListAddAC(3,1,$cid,0);
}


	//显示产品信息
    public function Cpcontent() {
		$plan= M('plan');
		$fck = M('fck');
		$product = M ('product');
		$PID = (int) $_GET['id'];
		if (empty($PID)){
			$this->error('错误!');
			exit;
		}
		$fck = M('fck');
		$map['id'] = $_SESSION[C('USER_AUTH_KEY')];
		$f_rs = $fck->where($map)->find();

		$where = array();
		$where['id'] = $PID;
		$where['yc_cp'] = array('eq',0);
		$prs = $product->where($where)->field('*')->find();
    $fee=M('fee');
    $fee_re=$fee->find();
    $s5=explode('|',$fee_re['s5']);//打折数量
    $dazhe=$s5[$f_rs['u_level']-1]/10;
    if($prs['is_dz']){
      $prs['dazhe']=$prs['money']*$dazhe;
    }
		if ($prs){
			$this->assign('prs',$prs);
        	$w_money = $prs['a_money'];
			$cc[$prs['id']] = $w_money;
	        $this->assign('cc',$cc);

			$this->assign('f_rs', $f_rs);
			$this->display();
		}
	}

    public function Buycp() {
        return false;

        //购买产品页
		$tplist = M('cptype')->where('status=0 and class=1')->field('id,tpname')->field("id,tpname")->order('id asc')->select();
        $field = "id,img,money,name";
        //奖金
        $fcks=D('Fck');
        $bid = $fcks->_getTimeTableList(0,1);

        /*$money = $fcks->y_fenh($bid);*/       //判断是否进行月分红
        //$fcks->dsqgfenh($money);             //董事全球分红
        //$fcks->zjqgfenh($money);             //总监全球分红
        //$fcks->Q_Spand();                   //重复消费清0

        foreach ($tplist as $productType){
            $allProduct[$productType['id']] = M('product')->where("cptype={$productType['id']} and id>1")->field($field)->limit(4)->order('cid asc,id desc')->select();
        }
        $this->assign('productType',$tplist);
        $this->assign('allProduct',$allProduct);
		$this->display();
	}

    /**
     * 每个分类下的所有商品，Buycp前台只显示最后上传的4条商品信息
     * productType  前台传入cptype表id
     */
    public function mach_goods(){
        //一级
        $type = (int)I('productType');
        $product = M('product');


        $goods_name = trim($_POST['keyword']);
        $map = array();
        if (!empty($goods_name)){
            import ( "@.ORG.KuoZhan" );  //导入扩展类
            $KuoZhan = new KuoZhan();
            if ($KuoZhan->is_utf8($goods_name) == false){
                $goods_name = iconv('GB2312','UTF-8',$goods_name);
            }
            unset($KuoZhan);
            $map['name'] = array('like',"%".$goods_name."%");
        }

        //一级
        $map['cptype'] = $type;
        $this->assign('productType',$type);

        //二级
        $two = (int)I('two');
        if (!empty($two)){
            $map['cptype2'] = $two;
        }

        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $product->where($map)->count();//总页数
        $listrows = 10;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $product->where($map)->order('id desc')->field('img,name,money,id')->page($Page->getPage().','.$listrows)->select();


        $this->assign('list',$list);
        $this->assign('productType',$type);

        //搜索二级导航
        $erji = M('cptype')->where('shuyu_1='.$type.' and class=2')->select();
        $this->assign('erji',$erji);

        $this->display();
    }

	public function newpay(){
        $this->display();
    }

	public function shopCar(){
		$pora = M('product');
		$fck = M('fck');
        $collection= M('collection');

		$id = $_SESSION[C('USER_AUTH_KEY')];
        $arr=$collection->where('uid='.$id)->select();
        if(empty($arr)){
            $url = __URL__.'/Buycp';
            $this->_box2(0,'您的购物车里没有商品！',$url,1);
            exit;
        }
        $f_rs=$fck->where('id='.$id)->find();
        $fee=M('fee');
        $fee_re=$fee->find();
        $s5=explode('|',$fee_re['s5']);//打折数量
        $dazhe=$s5[$f_rs['u_level']-1]/10;
        foreach ($arr as $v){
            $info[$v['id']] = $pora->where('id='.$v['pid'])->find();
            $info[$v['id']]['num'] = $v['num'];
            $info[$v['id']]['order_id'] = $v['id'];
            $info[$v['id']]['cptype'] = $v['cptype'];
            if($info[$v['id']]['is_dz']){
              $info[$v['id']]['money'] = $info[$v['id']]['money']*$dazhe;
            }
        }

		$this->assign('arr',$arr);
		$this->assign('info',$info);

		$this->display();

	}

	public function tixian(){
		
		$fck = M('fck');
		$card= M('card');
		$id = $_SESSION[C('USER_AUTH_KEY')];
        $arr=$fck->where('id='.$id)->field('b0')->find();	
		$this->assign('arr',$arr);
		$rsd = $card -> where('bid='.$id)->find();
        $this -> assign('rsd',$rsd);
		
		$this->display();

	}
	public function jiaoyi_chu(){
		$fck = M('fck');
		$where = array();
		$ID = $_SESSION[C('USER_AUTH_KEY')];
		$where['id'] = $ID;
		$field = '*';
		$rs = $fck ->where($where)->field($field)->find();

		$this->assign('rs',$rs);
		$this->display ();
	}
	public function jiaoyi_jilu(){
		$feng = M('fenhong');
		$cashpp = M('cashpp');
        $ID = $_SESSION[C('USER_AUTH_KEY')];
		$where = array();
		$where['uid'] = $ID;
		$field = '*';
		$rs = $cashpp->where($where)->field($field)->select();
		$this->assign('rs',$rs);

		$where1 = array();
		$where1['uid'] = $ID;
		$where1['f_num']=0;
		$field = '*';

		$rd = $feng ->where($where1)->field($field)->select();
		$this->assign('rd',$rd);


		$this->display ();
	}
   public function jiaoyi(){
		$cashpp = M('cashpp');
		$where = array();
		$where['money'] =array('gt',0);
		$field = '*';
		$rs = $cashpp ->where($where)->field($field)->select();	
		$this->assign('rs',$rs);
		$this->display ();
	}
	public function my_jinguo(){
		$cash = M('cash');
		$fee=M('fee')->field('s7')->find();
		$s7=$fee['s7'];
		$ID = $_SESSION[C('USER_AUTH_KEY')];
		$where = array();
		$where['user_id'] =$ID;
		$field = '*';
		$rs = $cash ->where($where)->field($field)->select();
	
		$this->assign('rs',$rs);
	
		$this->display ();
	}
	public function chongzhi_jilu(){
        $gp_order = M('gp_order');

        $id = $_SESSION[C('USER_AUTH_KEY')];
        $where     = array();
        $where['fck_id']  = $id;
        $where['is_pay']  = 1;
        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $gp_order->where($where)->count();//总页数
        $listrows = 5;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $gp_order->where($where)->order('id desc')->page($Page->getPage().','.$listrows)->select();
        $this->assign('list',$list);

		$this->display ();
	}

	public function jifenka(){
        $gp_order = M('gp_order');

        $id = $_SESSION[C('USER_AUTH_KEY')];
        $where     = array();
        $where['fck_id']  = $id;
        $where['is_pay']  = 1;
        $where['type']    = 0;
        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $gp_order->where($where)->count();//总页数
        $listrows = 5;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $gp_order->where($where)->order('id desc')->page($Page->getPage().','.$listrows)->select();
        $this->assign('list',$list);

		$this->display ();
	}
	public function tixian_jilu(){
		
		$tiqu = M('tiqu');
		$ID = $_SESSION[C('USER_AUTH_KEY')];
	   
	    $where = array();
		$where['uid'] =$ID;
		$field = '*';
		$rs = $tiqu ->where($where)->field($field)->select();
		$this->assign('rs',$rs);


		$this->display ();
	}
	public function zijin(){
		$this->display();
	}

	public function delBuyList(){
		$collection=M('collection');

		$uid=$_GET['id'];

	    $aa=$collection->where('id='.$uid)->delete();
	    
       if($aa){
	         $this->success("删除成功！");
       }
		
		
	}

	public function delBuyList_all(){

        //处理提交按钮
        $action = $_POST['action'];

        switch ($action) {

            case '删除';
                //获取复选框的值
                $c_oid = $_POST['oid'];
                if (!isset($c_oid) || empty($c_oid)){
                    $bUrl = __URL__.'/shopCar';
                    $this->_box(0,'请选择订单！',$bUrl,1);
                    exit;
                }

                $collection=M('collection');
                $where['id'] = array ('in',$c_oid);
                $aa=$collection->where($where)->delete();
                if($aa){
                    $this->success("删除成功！");
                }
            break;
            case '确认订单';
                //获取复选框的值
                $c_oid = $_POST['oid'];
                if (!isset($c_oid) || empty($c_oid)){
                    $bUrl = __URL__.'/shopCar';
                    $this->_box(0,'请选择订单！',$bUrl,1);
                    exit;
                }
                $this->ShoppingListAdd($c_oid);
            break;
            case '结算';
                $c_oid = $_POST['oid'];
                if (!isset($c_oid) || empty($c_oid)){
                    $bUrl = __URL__.'/shopCar';
                    $this->_box(0,'请选择订单！',$bUrl,1);
                    exit;
                }
                $this->ShoppingListAdd($c_oid);
                // $this->pay_order(1);
            break;
        }

	}
	public function reset(){
	    $collection = M('collection');
	    $id = $_SESSION[C('USER_AUTH_KEY')];
	    $aa=$collection->where('uid='.$id)->delete();
	if($aa){
//		$url = __URL__.'/Buycp';
		$this->success("清空完成！");
	}
}
	public function eb_sell(){
		//$fck = M('fck');
		//$plan = M('plan');
		$cashpp = M ('cashpp');
		//$gouwu= M('gouwu');
		$ePoints = (int) trim($_POST['ePoints']);
		
		$id=$_POST['id'];
		$where=array();
		$where['id'] = $id;
		$field ='*';
		$aa = $cashpp ->where($where)->field($field)->find();
		$money=$aa['money'];
		if (empty($ePoints) || !is_numeric($ePoints)){
			$this->error('数量不能为空!');
			exit;
		}
		if ($ePoints <= 0){
			$this->error ('数量输入不正确!');
			exit;
		}
		if ($ePoints>$money){
			$this->error ('商品库存不足!');
			exit;
		}
        $this->ShoppingListAddAC(3,$ePoints,1,$id);
		
	}
		
	
	public function chang(){
		$ID = $_GET['DID'];
		$nums = $_GET['nums'];
		$arr = $_SESSION["shopping"];
		$rs = explode('|',$arr);
		$shopping_id = '';
		foreach ($rs as $key=>$vo){
			$str = explode(',',$vo);
			if($str[0] == $ID){
				$str[1] = $nums;
			}
			$s_id = $str[0].','.$str[1];
			if(empty($shopping_id)){
				$shopping_id = $s_id;
			}else{
				$shopping_id .= '|'.$s_id;
			}
		}
		$_SESSION["shopping"] = $shopping_id;
	}

	public function chang_bz(){
		$ID = $_GET['DID'];
		$nums = trim($_GET['bzz']);

		if (!empty($nums)){
			import ( "@.ORG.KuoZhan" );  //导入扩展类
            $KuoZhan = new KuoZhan();
            if ($KuoZhan->is_utf8($nums) == false){
                $nums = iconv('GB2312','UTF-8',$nums);
            }
            unset($KuoZhan);
		}
		if(empty($_SESSION["shopping_bz"])){
			$_SESSION["shopping_bz"] = $ID.",".$nums;
		}
		$arr = $_SESSION["shopping_bz"];

		$rs = explode('|',$arr);
		$shopping_id = '';
		$tong = 0;
		foreach ($rs as $key=>$vo){
			$str = explode(',',$vo);
			if($str[0] == $ID){
				$tong = 1;
				$str[1] = $nums;
			}
			$s_id = $str[0].','.$str[1];
			if(empty($shopping_id)){
				$shopping_id = $s_id;
			}else{
				$shopping_id .= '|'.$s_id;
			}
		}
		if($tong==0){
			$shopping_id .= "|".$ID.",".$nums;
		}
		$_SESSION["shopping_bz"] = $shopping_id;
	}

	public function pay_order(){
	    $gouwu = M('gouwu');
	    $id = $_SESSION[C('USER_AUTH_KEY')];
	    $where     = array();
	    $where['uid']  = $id;
	    $where['have_pay']  = 0;
        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $gouwu->where($where)->count();//总页数
        $listrows = 5;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $gouwu->where($where)->order('id asc')->page($Page->getPage().','.$listrows)->select();
        $this->assign('list',$list);

        $pro = M('product');
        foreach ($list as $item){
            $product[$item['id']] = $pro->where('id='.$item['did'])->field('img,cptype,id')->find();
            $product[$item['id']]['money']=$product[$item['id']]['money']*$dazhe;
        }


        if ( $list == null){
            $bUrl = __URL__.'/shopCar';
            $this->_box1(1,'暂时没有订单，请先确认订单！',$bUrl,1);
            exit;
        }


        $this->assign('product',$product);

        $this->display('Gouwu/pay_order');
    }
    public function pay_order1(){
      $id = $_SESSION[C('USER_AUTH_KEY')];
      $gouwu = M('gouwu');

      $where     = array();
      $where['uid']  = $id;
      $where['have_pay']  = 1;
        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $gouwu->where($where)->count();//总页数
        $listrows = 5;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $gouwu->where($where)->order('id asc')->page($Page->getPage().','.$listrows)->select();
        $this->assign('list',$list);

        $pro = M('product');
        foreach ($list as $item){
            $product[$item['id']] = $pro->where('id='.$item['did'])->field('img,cptype,id')->find();
            $product[$item['id']]['money']=$product[$item['id']]['money']*$dazhe;
        }

        if ( $list == null){
            // $bUrl = __URL__.'/shopCar';
            // $this->_box1(1,'暂时没有订单，请先确认订单！',$bUrl,1);
             $this->pay_order();
            exit;
        }


        $this->assign('product',$product);

        $this->display('Gouwu/pay_order');
    }



  public function pay_orders1(){
      $gouwu = M('gouwu');
      $id = $_SESSION[C('USER_AUTH_KEY')];
      $order = M('address')->where('uid='.$id.' and moren=1')->find();
        $this->assign('order',$order);
      $where     = array();
      $where['uid']  = $id;
      $where['have_pay']  = 0;
        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $gouwu->where($where)->count();//总页数
        $listrows = 5;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $gouwu->where($where)->order('id desc')->limit(1)->select();
        $this->assign('list',$list);


        $pro = M('product');
        foreach ($list as $item){
            $product[$item['id']] = $pro->where('id='.$item['did'])->field('img,cptype,id')->find();
            $product[$item['id']]['money']=$product[$item['id']]['money']*$dazhe;
        }


        if ( $list == null){
            $bUrl = __URL__.'/shopCar';
            $this->_box1(1,'暂时没有订单，请先确认订单！',$bUrl,1);
            exit;
        }


        $this->assign('product',$product);

        $this->display('Gouwu/pay_order1');
    }
	public function ShoppingListAdd($oid){
		$id = $_SESSION[C('USER_AUTH_KEY')];

		$fck = M('fck');
		$fck_rs = $fck->where('id='.$id)->find();
		$this->assign('fck_rs',$fck_rs);

		$pora = M('product');

        $collection =M('collection');
	    $dlist = $collection -> where('uid='.$id) ->select();
        $this->assign('dlist',$dlist);


        $address = M('address')->where('uid='.$id)->find();
        
        
        for ($i=0;$i<count($oid);$i++){
 
            $p[$i] = $collection->where('id='.$oid[$i])->field('pid,num,us_name,us_tel,us_address')->find();
            if(empty($p[$i]['us_name'])){
              $us_name = $address['name'];
            }
            if(empty($p[$i]['us_tel'])){
              $us_tel = $address['tel'];
            }
            if(empty($p[$i]['us_address'])){
              $us_address = $address['address'];
            }
            //添加收货地址
        $data = array('us_name'=>$us_name,'us_address'=>$us_address,'us_tel'=>$us_tel);
         if ( empty($p[$i]['us_name']) || empty($p[$i]['us_tel']) || empty($p[$i]['us_address'])){
             $res = M('collection')->where("id=$oid[$i]")->setField($data);
        }

        $p[$i] = $collection->where('id='.$oid[$i])->field('pid,num,us_name,us_tel,us_address')->find();
            $path[$i] = $p[$i]['pid'];
            $pnum[$i] = $p[$i]['num'];
            $us_name[$i] = $p[$i]['us_name'];
            $us_tel[$i] = $p[$i]['us_tel'];
            $us_address[$i] = $p[$i]['us_address'];
            if ( empty($p[$i]['us_name']) || empty($p[$i]['us_tel']) || empty($p[$i]['us_address'])){
                $bUrl = __URL__.'/shopCar';
                $this->_box(1,'您有未完善收货信息的订单，请先填写收货地址！',$bUrl,1);
                exit;
            }
        }

        $gouwu = M('gouwu');
        $gwd = array();
        $gwd['uid'] = $id;
        $gwd['user_id'] = $fck_rs['user_id'];
        $gwd['lx'] = 1;
        $gwd['ispay'] = 0;
        $gwd['pdt'] = mktime();
        $where = array();
        $fee=M('fee');
        $fee_re=$fee->find();
        $s5=explode('|',$fee_re['s5']);//打折数量
        $dazhe=$s5[$fck_rs['u_level']-1]/10;
        for ($i=0;$i<count($path);$i++){
            $where['id'] = array('eq',$path[$i]);
            $prs = $pora->where($where)->find();
            //判断是否打折
            if(!$prs['is_dz']){
              $dazhe=1;
            }else{
              $dazhe=$s5[$fck_rs['u_level']-1]/10;
            }

            $gwd['order_id'] = $this->_getPPOrderID();
            $w_money = $prs['money'];
            $gwd['did'] = $prs['id'];
            $gwd['money'] = $w_money*$dazhe;
            $gwd['pvzhi'] = $gwd['money'];
            $gwd['shu'] = $pnum[$i];
            $gwd['cprice'] = $pnum[$i]*$w_money*$dazhe;
            $gwd['pvzhi'] = $gwd['cprice'];
            if($prs['pv'] != 0){
                $gwd['pvzhi'] = $pnum[$i]*$prs['pv']*$dazhe;
            }
            $gwd['us_name'] = $us_name[$i];
            $gwd['us_address'] = $us_address[$i];
            $gwd['us_tel'] = $us_tel[$i];

            if(!empty($prs['countid'])){
                $gwd['countid'] = $prs['countid'];
            }
            $gouwu->add($gwd);
            $collection->where('id='.$oid[$i])->delete();

        }
        // $bUrl = __URL__.'/pay_order';
        // $this->_box(1,'已成功生成订单，请点完成付款操作！',$bUrl,1);
        $this->pay_order();

	}
    //生成匹配订单编号
    public function _getPPOrderID(){
        $cash = M('gouwu');

        $firststr = $this->createRandomStr(1);
        $mynn = $firststr.rand(100000000,999999999);

        $fwhere['order_id'] = $mynn;
        $frss = $cash->where($fwhere)->field('id')->find();
        if ($frss){
            return $this->_getPPOrderID();
        }else{
            unset($cash);
            return $mynn;
        }
    }

    private function createRandomStr($length){
        $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';//62个字符
        $strlen = 26;
        while($length > $strlen){
            $str .= $str;
            $strlen += 26;
        }
        $str = str_shuffle($str);
        return substr($str,0,$length);
    }
//	public function ShoppingListAdd(){
//		$address = M('address');
//		$id = $_SESSION[C('USER_AUTH_KEY')];
//		$aList = $address->where('pid='.$id)->find();
//		$this->assign('aList',$aList);
//
//		$fck = M('fck');
//		$fck_rs = $fck->where('id='.$id)->find();
//		$this->assign('fck_rs',$fck_rs);
//
//		$pora = M('product');
//		$arr =M('gouwu');
//	    $dlist = $arr -> where('uid='.$id) ->select();
//
//        $this->assign('dlist',$dlist);
//		$where['id'] = array('in','0'. $path .'0');
//		$list = $pora -> where($where) ->select();
//		foreach ($list as $lvo){
//			$w_money = $lvo['a_money'];
//			//物品总价
//			$ep[$lvo['id']] = $ids[$lvo['id']] * $w_money;
//
//			//所有商品总价
//			$eps += $ids[$lvo['id']] * $w_money;
//			$sum += $ids[$lvo['id']];
//
//			$cc[$lvo['id']] = $w_money;
//		}
//
//		$this->assign('cc',$cc);
//
//
//		$this->assign('list',$list);
//		$this->assign('path',$path);
//		$this->assign('ids',$ids);
//		$this->assign('sum',$sum);
//		$this->assign('eps',$eps);
//		$this->assign('ep',$ep);
//
//		$this -> display('ShoppingListAdd');
//
//	}


	public function eb_sell_AC(){
		$ePoints = (int) trim($_POST['ePoints']);
		
		$fck = M ('fck');
		$cashpp = M ('cashpp');
		$history = M ('xfhistory');

        $where = array();
		$ID = $_SESSION[C('USER_AUTH_KEY')];
		//查询条件
		$where['id'] = $ID;
		$field ='*';
		$fck_rs = $fck ->where($where)->field($field)->find();
		if (!$fck_rs){
			$this->error('会员信息错误！');
			exit;
		}
		if (empty($ePoints) || !is_numeric($ePoints)){
			$this->error('数量不能为空!');
			exit;
		}
		if (strlen($ePoints) > 12){
			$this->error ('数量太大!');
			exit;
		}
		if ($ePoints <= 0){
			$this->error ('数量输入不正确!');
			exit;
		}
		if ($fck_rs['b1'] < $ePoints){
			$this->error('果实数量不足!');
			exit;
		}
		$nowdate = strtotime(date('c'));
		//开始事务处理
		$cashpp->startTrans();
        $ePoints1=$fck_rs['b1']-$ePoints;
		$data					= array();
		$data['uid']			= $fck_rs['id'];
		$data['rdt']			= $nowdate;
		$data['money']			= $ePoints;
		$data['money_two']			= $ePoints1;
		$rs2 = $cashpp->add($data);
		unset($data);
		if ($rs2){
		    $fck->execute("UPDATE __TABLE__ SET b1=b1-".$ePoints." WHERE id=".$fck_rs['id']."");
		    $fck->execute("UPDATE __TABLE__ SET b0=b0+".$ePoints." WHERE id=".$fck_rs['id']."");
			
			$cashpp->commit();
			$bUrl = __URL__.'/jiaoyi_jilu';
			$this->_box(1,'果实卖出成功！',$bUrl,1);
			exit;
		}else{
			//事务回滚：
			$cashpp->rollback();
			$this->error('果实卖出失败！');
			exit;
		}
	}

	
public function ShoppingListAddAC($type,$nums,$cid,$did){

        if ($nums==0 ||$nums == null){
            $this->error("数量不能为0");
        }

        $collection = M('collection');

        $data['uid'] = $_SESSION[C('USER_AUTH_KEY')];
        $data['pid'] = $cid;
        $data['num'] = $nums;
        $data['time'] = time();
        $oid = $collection->add($data);
        
        $id = $_SESSION[C('USER_AUTH_KEY')];

    $fck = M('fck');
    $fck_rs = $fck->where('id='.$id)->find();
    $this->assign('fck_rs',$fck_rs);

    $pora = M('product');

        $collection =M('collection');
      $dlist = $collection -> where('uid='.$id) ->select();
        $this->assign('dlist',$dlist);


        $address = M('address')->where('uid='.$id.' and moren=1')->find();
        
      
          $p = $collection->where('id='.$oid)->field('pid,num,us_name,us_tel,us_address')->find();
           // 添加收货地址
        $data = array('us_name'=>$address['name'],'us_address'=>$address['address'],'us_tel'=>$address['tel']);
         if ( empty($p['us_name']) || empty($p['us_tel']) || empty($p['us_address'])){
             $res = M('collection')->where("id=$oid")->setField($data);
        }
        $p = $collection->where('id='.$oid)->field('pid,num,us_name,us_tel,us_address')->find();
            $path = $p['pid'];
            $pnum = $p['num'];
            $us_name = $p['us_name'];
            $us_tel = $p['us_tel'];
            $us_address = $p['us_address'];
            if ( empty($p['us_name']) || empty($p['us_tel']) || empty($p['us_address'])){
               //删除购物车
                $collection->where('id='.$oid)->delete();
                $bUrl = __URL__.'/dizhi';
                $this->_box(1,'您有未完善收货信息的订单，请先填写收货地址！',$bUrl,1);
                exit;
            }
  

        $gouwu = M('gouwu');
        $gwd = array();
        $gwd['uid'] = $id;
        $gwd['user_id'] = $fck_rs['user_id'];
        $gwd['lx'] = 1;
        $gwd['ispay'] = 0;
        $gwd['pdt'] = mktime();
        $where = array();

            $where['id'] = array('eq',$path);
            $prs = $pora->where($where)->find();
            //判断是否打折

            $gwd['order_id'] = $this->_getPPOrderID();

            $w_money = $prs['money'];
            $gwd['did'] = $prs['id'];
            $gwd['money'] = $w_money;
            $gwd['shu'] = $pnum;
            $gwd['cprice'] = $pnum*$w_money;
            $gwd['pvzhi'] = $gwd['cprice'];
            if($prs['pv'] != 0){
              $gwd['pvzhi'] = $pnum*$prs['pv'];
            }
            $gwd['us_name'] = $us_name;
            $gwd['us_address'] = $us_address;
            $gwd['us_tel'] = $us_tel;

            if(!empty($prs['countid'])){
                $gwd['countid'] = $prs['countid'];
            }
           $form_rs = $gouwu->add($gwd);
           //删除购物车
           $collection->where('id='.$oid)->delete();

        if ($form_rs){
          $form_rs= array($form_rs);
            $url = __URL__.'/pay_orders1';
            $this->_box(0,'已成功生成订单，请点完成付款操作！',$url,1);
        }else{
            $this->error('生成订单失败,请返回上一步操作！');
            exit;
        }


	}


    public function _getOrderID_perfix($perfix){
        $cash = M('gp_order');
        $mynn = $perfix.rand(100000,999999);

        $fwhere['order_id'] = $mynn;
        $frss = $cash->where($fwhere)->field('id')->find();
        if ($frss){
            return $this->_getOrderID_perfix($perfix);
        }else{
            unset($cash);
            return $mynn;
        }
    }
	//购买公排
	public function buy_gp(){


		$fck = M('fck');

		$id =  $_SESSION[C('USER_AUTH_KEY')];

		if ($id == null){
		    $this->error('请先登录系统！');
        }
		$fck_rs=$fck->where('id='.$id)->find();

        $fee_rs = M('fee')->field('str1')->find();


        $order_id=date('Ymd').$this->_getOrderID_perfix($id);
		$gp_order = M('gp_order');
        $data                  = array();
        $data['fck_id']        = $id;
        $data['appid']         = $fck_rs['appid'];
        $data['user_id']       = $fck_rs['user_id'];
        $data['order_id']      = $order_id;
        $data['create_time']   = time();
        $data['money']         = $fee_rs['str1'];
        $data['number']        = 1;


        $result=$gp_order->add($data);


		if($result){
			//redirect('/Gouwu/ShoppingListAdd', 5, '生成订单成功...')
			$url = __URL__.'/buy_order_info';
//			$url = __URL__.'/gpai';
			$this->_box(0,'生成订单成功！',$url,1);
			exit;
		}else{
			$this->error('生成订单失败');
		}

	}



    public function buy_order_info(){

        $id = $_SESSION[C('USER_AUTH_KEY')];


        $gp_order = M('gp_order');

        $where           =   array();
        $where['fck_id']  = $id;
        $where['is_pay'] = 0;
        $where['type']   = 0;

        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $gp_order->where($where)->count();//总页数
        $listrows = 5;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $gp_order->where($where)->order('id asc')->page($Page->getPage().','.$listrows)->select();
        $this->assign('list',$list);
        $this->display();

    }
    //公排订单信息
    public function gp_order(){

        $id = $_SESSION[C('USER_AUTH_KEY')];

        if ($id == null){
            $this->error('请先登录系统！');
        }

        $gp_order = M('gp_order');

        $where           =   array();
        $where['fck_id']  = $id;
        $where['type']   = 0;


        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $gp_order->where($where)->count();//总页数
        $listrows = 5;//每页显示的记录数
        $Page = new ZQPage($count, $listrows, 1, 0, 3);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $gp_order->where($where)->order('is_pay asc,id desc')->page($Page->getPage().','.$listrows)->select();

        $this->assign('list',$list);
        $this->display();

    }

    public function order_details(){
        $gp_order = M('gp_order');
        $id = (int)$_GET['oid'];
        $rs  = $gp_order->where('id='.$id)->find();
        $this->assign('rs',$rs);
        $this -> display();
    }

    /**
     * 购物订单详情
     */
    public function gw_order_info(){
        $gouwu = M('gouwu');
        $id = (int)$_GET['ID'];
        $rs  = $gouwu->where('id='.$id)->find();
        $this->assign('rs',$rs);
        $productId = I('imgId');
        $this->assign('img',M('product')->where("id={$productId}")->getField('img'));
        $this -> display();
    }

    public function change_receive_info(){
        $gouwu = M('gouwu');
        $type= (int)$_POST['type'];
        $oid = (int)$_POST['oid'];
        $val = trim($_POST['val']);
        if ( empty($val)){
            echo "修改信息不能为空！";
            exit();
        }
        $info = $gouwu->where('id='.$oid)->field('have_pay')->find();
        if ($info){
            if ($info['have_pay'] !=0){
                echo "已支付的订单不可修改收货信息！";
                exit();
            }
        }else{
            echo "未找到订单信息！";
            exit();
        }
        if ($type == 1){
            $rs = $gouwu->where('id='.$oid)->setField('us_name',$val);
            if ($rs){
                echo "修改成功！";
            }else{
                echo "修改失败！";
            }
        }elseif($type == 2){
            $rs = $gouwu->where('id='.$oid)->setField('us_tel',$val);
            if ($rs){
                echo "修改成功！";
            }else{
                echo "修改失败！";
            }
        }elseif($type == 3){
            $rs = $gouwu->where('id='.$oid)->setField('us_address',$val);
            if ($rs){
                echo "修改成功！";
            }else{
                echo "修改失败！";
            }
        }else{
            echo "数据错误";
        }
    }

    public function del_order(){
        $gp_order = M('gp_order');

        $id = (int)$_GET['ID'];

        $rs  =   $gp_order->where("id=".$id)->delete();
        if($rs){
            $url = __URL__.'/buy_order_info';
            $this->_box(1,'删除订单成功！',$url,1);
            exit;
        }else{
            $this->error('删除订单失败');
        }
    }
    public function del_gw_order(){
        $gouwu = M('gouwu');

        $id = (int)$_GET['ID'];

        $have_pay = $gouwu->where("id={$id}")->getField('have_pay');
        if ($have_pay==1){
            $url = __URL__.'/pay_order';
            $this->_box(1,'订单已支付，不可删除！',$url,1);
            exit;
        }
        $rs  =   $gouwu->where("id=".$id)->delete();
        if($rs){
            $url = __URL__.'/pay_order';
            $this->_box(1,'删除订单成功！',$url,1);
            exit;
        }else{
            $this->error('删除订单失败');
        }
    }

public function tixianAC(){
			$money=$_POST['money'];
			
			$pid=$_SESSION[C('USER_AUTH_KEY')];
			$id=$_SESSION['login_count'];
            

			$fck = M ('fck');
			$where['id']=$pid;
			$users=$fck->where($where)->field('b0')->find();
            $t=100;
            if ($money % $t) {
				$this->error('提现金额必须是 '.$t."的整数倍");
				exit;
			}


			if($users['b0']<$money){
				$this->error('您的金币余额不足！');
				exit;
			}
            if (empty($money) || !is_numeric($money)){
			   $this->error('金额不能为空!');
			   exit;
		    }
		    if ($money <= 0){
			   $this->error ('金额输入不正确!');
			   exit;
		    }

			import('@.ORG.WXHB');
			$wxhb=new WXHB();
			$t=$money*0.05;
            $ePoints=$money-$t;
			
			
			$info=$wxhb->send($id,$ePoints);
			
		/*	echo '===='.$info.'====';
			$info_arr=simplexml_load_string($info);
			foreach($info_arr->children() as $childItem) {
				echo $childItem->getName() . "->".$childItem."<br />";
			}*/
		
	}
    public function umall(){
        
        $id=$_SESSION[C('USER_AUTH_KEY')];
		$fck=M('fck');
		$product=M('product');
		$rs = $fck -> where('id='.$id)->field('is_pay,b0,u_level') -> find();
	//	if($rs['u_level']<1){
          // $this->myrz();
			//exit;

		//}
        $this -> assign('rs',$rs);
        $rsd = $product -> where('cid>3')->select();
        $this -> assign('rsd',$rsd);
        $this->display ();
	}
	 public function umallAC(){
	 	$pid=$_POST['id'];
		$shu=$_POST['shu'];


		print_r($pid);
		exit;
		$fck=M('fck');
         $id=$_SESSION[C('USER_AUTH_KEY')];
         $rs = $fck -> where('id='.$id)->field('b4') -> find();
		 $money=$_POST['money'];
		if($money!=$rs['b4']){
			$this->error('产品需一次性买完!');
			exit;
		}
 
        $id=100000;
		$shop=M('fck_shop');


		$product=M('product');
		$where1 = array();
	    $where1['id'] = array ('in',$pid);
		$pdd=$product->where($where1)->select();
		
		foreach ($pdd as $proo) {
		$i==0;
		
        $gwd1 = array();
        $gwd1['did'] = $id;
        $gwd1['uid'] = $proo['id'];
       
        $gwd1['pdt'] = time();
        $gwd1['price'] = $proo['a_money'];    
        $gwd1['num'] = $shu[$i];
        $gwd1['content']=$proo['img'];

        $result1=$shop->add($gwd1);
       	 $i++; 
        }
    
	}
    public function wsmall(){
    	$id=$id=$_SESSION[C('USER_AUTH_KEY')];
    	$fck=M('fck');
    	$rs = $fck -> where('id='.$id)->field('re_id') -> find();
    	$aaa=$fck -> where('id='.$rs['re_id'])->field('u_level') -> find();
        $this -> assign('u_level',$aaa['u_level']);

        $list=$fck -> where('u_level>0') -> select();
        $this -> assign('list',$list);
        $this->display();

     
       
	}
    public function Mall(){
    	$id=$_GET['id'];
    	$shop=M('fck_shop');
    	$fck=M('fck');
    	$aa = $fck -> where('id='.$id)->field('nickname')->find();
        $this -> assign('nickname',$aa['nickname']);
    	$rs = $shop -> where('did='.$id)->select();

        $this -> assign('rs',$rs);
        $this->display();

     
       
	}


	public function myrz(){
     
       $this->display ('Gouwu/myrz');
	}


	public function user_money(){
        $id=$_SESSION[C('USER_AUTH_KEY')];
		$fck=M('fck');
		$rs = $fck -> where('id='.$id) -> find();
        $this -> assign('rs',$rs);
       $this->display ();
	}
	public function czAC(){
		$fck = M('fck');
		$id =  $_SESSION[C('USER_AUTH_KEY')];
		$fck_rs = $fck->where('id='.$id)->find();

		$ePoints = trim($_POST['amount']);

		if (empty($ePoints) || !is_numeric($ePoints)){
			$this->error('数量不能为空!');
			exit;
		}
		if ($ePoints <= 0){
			$this->error ('数量输入不正确!');
			exit;
		}
		if ($ePoints <= 10){
		//	$this->error ('充值金额不能低于10元!');
			//exit;
		}




        $order_id=date('Ymd').$this->_getOrderID_perfix($id);
        $gp_order = M('gp_order');
        $data                  = array();
        $data['fck_id']        = $id;
        $data['appid']         = $fck_rs['appid'];
        $data['user_id']       = $fck_rs['user_id'];
        $data['order_id']      = $order_id;
        $data['create_time']   = time();
        $data['money']         = $ePoints;
        $data['number']        = 1;
        $data['type']          = 1;   //充值

        $result=$gp_order->add($data);

        //删除一个小时前未完成支付的订单
        $time = time()- 3600;
        $where = array();
        $where['type'] = 1;
        $where['is_pay'] = 0;
        $where['create_time'] = array('elt',$time);
        $gp_order->where($where)->delete();
//        echo M()->_sql();
//        $or = $gp_order->field('id')->select();
//        var_dump($or);
        if ($result){
//            var_dump($result);exit();
            $url=U('Weixinpay/pay',array('out_trade_no'=>$result));
            redirect($url);
        }else{
            $url = __URL__.'/user_money';
            $this->_box(0,'申请充值失败！',$url,1);
            exit;
        }


//        $this->ShoppingListAddAC(4,$ePoints,1,0);
		
	}

	public function addAddress(){
		$address = M('address');
		$id =  $_SESSION[C('USER_AUTH_KEY')];
		$did = $_POST['ID'];

		$name = $_POST['name'];
		$are = $_POST['address'];
		$tel= $_POST['tel'];

		$data['uid'] = $name;
		//$data['name'] = $name;
		$data['address'] = $are;
		$data['tel'] = $tel;
		

		if(empty($did)){
			$result = $address->add($data);
		}else{
			$result = $address->where('pid='.$did)->save($data);
		}

		if($result){
			$url = __URL__.'/ShoppingListAdd';
			$this->_box(0,'修改成功！',$url,1);
			exit;
		}else{
			$this->error('修改失败');
		}

	}

	public function moren(){
		$address = M('address');
		$id =  $_SESSION[C('USER_AUTH_KEY')];
		$id = $_GET['ID'];
		$rs  = $address->where('id='.$id)->setField('moren',1);
		$rs2 = $address->where('id !='.$id.' and moren=1')->setField('moren',0);
		if($rs && $rs2){
			echo $id;
		}else{
			echo '0';
		}
	}
    public function ruzhu(){
		$fck = M('fck');
		$id =  $_SESSION[C('USER_AUTH_KEY')];
		$rs  = $fck->where('id='.$id)->find();
		$this->assign('rs',$rs);
		$this -> display();	
		
	}

    public function ruzhuAC(){
		$fck = M('fck');	
		$id = $_POST['id'];
		$u_level = $_POST['daili'];
		if($u_level==1){
			$nums=5000;
		}
        elseif($u_level==2){
			$nums=10000;
		}
		elseif($u_level==3){
			$nums=20000;
		}
        $a=$fck->where('id='.$id)->field('u_level')->find();
        if($a['u_level']>=$u_level){
           $this->error('您已经申请过该级别的代理了！');
           exit;
        }   
        $this->ShoppingListAddAC(5,$nums,3,$u_level);
		

	
	}

    public function  ShopAC(){

        $action = $_POST['example2'];
		$oid = (int)$_POST['pid'];
		$fck_id = (int)$_POST['fck_id'];

		if($action < 0){
			$this->error("您没有选择支付方式！");
			exit;
        }

        if($oid < 0){
			$this->error("订单信息返还错误！");
			exit;
        }


		switch ($action){
			case '1';
//				$url=U('Weixinpay/pay',array('out_trade_no'=>$oid));//微信支付
//                redirect($url);


                $gp_order = M('gp_order');
                $rs  = $gp_order->where('id='.$oid)->find();
                $aa = A('Alipayapi');
                $aa->doalipay($oid,"购买VIP购物卡",$rs['money']);


				break;

			case '2';
//				$this->ShopingSave(2,$money,$id);
				break;
				//测试使用支付方式
//            case '3';
//                $data = array('is_pay'=>1,'pay_time'=>time());
//                $res = M('gp_order')->where('id='.$oid)->setField($data);
//                if ($res){
////                        //添加权限
////                        M('fck')-> where("id=".$_SESSION[C('USER_AUTH_KEY')]." and id != 1 and is_boss !=1")->setField('is_boss',1);
////                        $use = A('YouZi');
////                        $use->_auditMenberOpenUser($_SESSION[C('USER_AUTH_KEY')]);
////                        //取消权限
//                    $fee_rs = M('fee')->field('s13')->find();
//
//                    for ($i=0;$i<$fee_rs['s13'];$i++){
//                        $rs = D('Fck')->create_info_fck2($fck_id,1);
//                    }
//                    if($rs){
////                        $url = __URL__.'/gpai';
//                        $url = __APP__.'/Gouwu/gp_order';
//                        $this->_box(1,'购买成功，已进入系统公排！',$url,1);
//                        exit;
//                    }else{
//                        $this->error('购买失败！');
//                    }
//                }
//				break;

		}




    }


    /**
     * 结算订单部分
     */
    public function  ShopAC_gw_order(){

        $action = $_POST['example2'];
		$oid = (int)$_POST['pid'];

		if($action < 0){
			$this->error("您没有选择支付方式！");
			exit;
        }
        if($oid < 0){
			$this->error("订单信息返还错误！");
			exit;
        }

        $gouwu = M('gouwu');
        $info = $gouwu->where('id='.$oid)->find();

        if ($info){
            if ($info['have_pay'] == 1 ){
                $this->error("订单已支付！");
                exit;
            }



            $fck_rs = M('fck')->where('id='.$info['uid'])->field('agent_cash,agent_use,p_path,id,user_id,u_level,is_pay')->find();

            if ($action == 1){
               //乐淘钱包 agent_cash
                if ( $fck_rs['agent_cash'] < $info['cprice']){
                    $this->error("余额不足！");
                    exit;
                }
                $res = $this->zijin_log($fck_rs['id'],$fck_rs['user_id'],"shop","购物支出",-$info['cprice'],"agent_cash");

            } elseif ($action == 2){
               //电子币  agent_use
                if ( $fck_rs['agent_use'] < $info['cprice']){
                    $this->error("余额不足！");
                    exit;
                }
                $res = $this->zijin_log($fck_rs['id'],$fck_rs['user_id'],"shop","购物支出",-$info['cprice'],"agent_use");


            }else{
                $this->error('资金支付类型有误！');
                exit();
            }

            if ($res){
                $data = array('have_pay'=>1,'have_pay_time'=>time(),'payType'=>$action);
                $an = $gouwu->where('id='.$oid)->setField($data);
                if ($an){

                    $fck = D('Fck');
                    //$fck->getusjj($fck_rs['id'],1,$info['pvzhi']);     //奖金结算
                    //$fck->leijiD($fck_rs['id'],1,$info['cprice']);     //累计消费


                    $product=M('product');
                    $p_rs=$product->where('id='.$info['did'])->find();
                    $lirun=$info['cprice']-$p_rs['a_money'];
                    $gouwu->execute("update __TABLE__ set yifanli=".$lirun." where id=".$oid);
                    $result = M('pingtai')->execute("update __TABLE__ set lirun=lirun+".$lirun." where id=1");  
//购买产品开通
        // if($fck_rs['is_pay']==0){
        //   $fee_rs = M('fee')->find();
        //   $s9 = explode('|', $fee_rs['s9']);
        //   $s11 = explode('|', $fee_rs['s11']);
        //   $cp = array_combine($s9,$s11);

        //   $floor = floor($info['cprice']);
        //   foreach ($s9 as $key2 => $value2) {
        //     if($floor==$value2){
        //       $u_level=$key2+1;
        //     }
        //   }
        //   $cpzj = $cp[$floor];

        // $ff = $this->gongpaixtsmall(1);
        // $data['father_id'] = $ff['father_id'];
        // $data['father_name'] = $ff['father_name'];
        // $data['treeplace'] = $ff['treeplace'];
        // $data['p_level'] = $ff['p_level'];
        // $data['p_path'] = $ff['p_path'];
        // $data['u_pai'] = $ff['u_pai'];
        // $data['is_pay'] = 1;
        // $data['u_level'] = $u_level;
        // $data['pdt'] = time();
        // $data['cpzj'] = $cpzj;
        // $result = M('fck')->where('id='.$info['uid'])->save($data);
        // if($result){
        //   $fckk = D('Fck');
        // $fckk->getusjj($info['uid']);
        // }

        // }


                    $url = __URL__.'/ShopCar';
                    $this->_box(1,'支付成功，请耐心等待系统发货！'.$code,$url,1);
                }else{
                    $url = __URL__.'/ShopCar';
                    $this->_box(1,'支付失败！',$url,1);
                }

            }
        }else{
            $this->error('订单信息返还错误！');
        }

    }


  //小公排
  public function gongpaixtsmall($uid){
    $fck = M ('fck2');
    $mouid=$uid;
    $field = 'id,user_id,p_level,p_path,u_pai';
    $where = 'is_pay>0 and (p_path like "%,'.$mouid.',%" or id='.$mouid.')';
  
    $re_rs = $fck ->where($where)->order('p_level asc,u_pai asc')->field($field)->select();
    $fck_where = array();
    foreach($re_rs as $vo){
      $faid=$vo['id'];
      $fck_where['is_pay']   = array('egt',0);
      $fck_where['father_id']   = $faid;
      $count = $fck->where($fck_where)->count();
      if ( is_numeric($count) == false){
        $count = 0;
      }
      if ($count<2){
        $father_id=$vo['id'];
        $father_name=$vo['user_id'];
        $TreePlace=$count;
        $p_level=$vo['p_level']+1;
        $p_path=$vo['p_path'].$vo['id'].',';
        $u_pai=$vo['u_pai']*2+$TreePlace;
  
        $arry=array();
        $arry['father_id']=$father_id;
        $arry['father_name']=$father_name;
        $arry['treeplace']=$TreePlace;
        $arry['p_level']=$p_level;
        $arry['p_path']=$p_path;
        $arry['u_pai']=$u_pai;
        return $arry;
        break;
      }
    }
  }

	public function  ShopingSave($type,$money,$oid){
		$Id = (int) $_SESSION[C('USER_AUTH_KEY')];
        $time=time();

		$pora = M('product');
		$address = M('address');
		$gouwu=M('gouwu');
		$fck = D('Fck');
		$cash=D('Cash');
		$plan=M('plan');
		$prices = $money;
		
		$gou = $gouwu->where("ccxhbz='".$oid."'") ->find();
		$pora_rs = $pora->where('cid=1') ->find();	
		$dj=$pora_rs['money'];
		$ePoints=$money/$dj;
		$fck_rs = $fck->where('id='.$Id) ->find();
        $u_level=$fck_rs['u_level'];



		if($type==2){
			$aa=$fck_rs['b0'];
			if($aa < $prices){
				echo $aa;
				echo $prices;
			$this->error("您的金币余额不足！");
			exit;
		}
		}
		elseif($type==3){
			$aa=$fck_rs['b1'];
			if($aa < $prices){
			$this->error("您的金果余额不足！");
			exit;
		}
		}
		elseif($type==4){
			$aa=$fck_rs['b2'];
			if($aa < $prices){
			$this->error("您的果卷余额不足！");
			exit;
		}
		}
         $address=M('address');
         $b=$address->where('pid='.$Id)->find();

		if(!$b){
	        $this->error('请先到个人资料处完善您的收货地址信息!谢谢！!');
			exit;
		    }
	/*	$rs = explode('|',$arr);
		$path = ',';
		foreach ($rs as $vo){
			$str = explode(',',$vo);
			$p_rs = $pora->where('id='.$str[0].'')->find();
			if(!$p_rs){
				$this->error("您所购买的产品暂时没货！");
				exit;
			}
		}
		$rs = explode('|',$arr);
		$path = ',';
		foreach ($rs as $vo){
			$str = explode(',',$vo);
			$path .= $str[0].',';
			$ids[$str[0]] = $str[1];
		}*/

		$fck_rs = $fck->where('id='.$Id) ->find();	
		$aid = $_POST['adid'];
	
		

		if($type==2){
			$rs = $fck->query("update __TABLE__ set b0=b0-".$prices." where id=".$Id);
		}
	    if($type==3){
			$rs = $fck->query("update __TABLE__ set b1=b1-".$prices." where id=".$Id);
		} 
		if($type==4){
			$rs = $fck->query("update __TABLE__ set b2=b2-".$prices." where id=".$Id);
		}	
		$fck->addencAdd($fck_rs['id'],$fck_rs['user_id'], -$prices,22);
		if($rs !== false){
			 if($gou['lx']==2 && $type==2){
			 	$data					= array();
		        $data['uid']			= $Id;
		        $data['rdt']			= time();
		        $data['user_id']        =$fck_rs['nickname'];
		        $data['money']			= $ePoints;
		        $data['epoint']			= 10;//存储国家，查询币值
		        $data['is_pay']			= 0;
		        $data['x1']	            =0;
		        $rs2 = $cash->add($data);
		        $fck->execute("UPDATE __TABLE__ SET b3=b3+".$ePoints." WHERE id=".$Id);
		        $fck->lingdaojiang($Id,$money);  
			 }
			 if($gou['lx']==4 && $type==2){

			 	$fck->execute("UPDATE __TABLE__ SET b2=b2+".$prices." WHERE id=".$Id);

                   $chongzhi=M('chongzhi');
                   $data = array();
                   $data['uid']     = $Id;
                  
                   $data['huikuan'] = $prices;
                   $data['rdt']     = time();
                   $data['is_pay']  = 0;
                   $data['zhuanghao']  = $oid;
                   $chongzhi->add($data); 
			 }
			 if($gou['lx']==5 && $type==2){

			 	   $fck->execute("UPDATE __TABLE__ SET u_level=".$gou['guquan'].",b4=".$prices." WHERE id=".$Id);

                    
			 }
			 
            if($gou['lx']==1){

                    $remit=M('remit');
                    $aa=$fck->where('id='.$Id)->find();
                    $name=$aa['nickname'];

                    $address=M('address');
                    $bb=$address->where('pid='.$Id)->find();


                    $tel=$bb['tel'];
                    $ad=$bb['address'];

                    $data                   = array();
                    $data['uid']            = $Id;
                    $data['b_uid']            = time();
                    $data['user_id']        = $name;
                    $data['orderid']          = $oid;
                    $data['or_time']         = $tel;
                    $data['amount']         = $prices;
                    $data['bankid']             =$ad;
                    $data['kh_money']             =0;
                    $remit->add($data);
                    
            }
		    $gouwu->query("update __TABLE__ set ispay=1,okdt=".$time." where ccxhbz='".$oid."'");
			
			$_SESSION["shopping"]='';
			$_SESSION["shopping_bz"]='';
			$url = __URL__.'/ShoppingListAdd/';
			$this->_box(1,'购买成功！',$url,1);
			exit;
		}else{
			$this->error("购买失败！");
			exit;
		}
	}

	public function BuycpInfo() {//购买信息
		$cp = M('product');
		$fck = M('fck');
        $fee=M('fee');
		$gouwu = M('gouwu');
		$id = $_SESSION[C('USER_AUTH_KEY')];
        $user=$fck->where('id='.$id)->find();
        $login_level=$user['re_level'];

        //======================================
        //自己的id和下面二代的id
        $id_array=array();//结果为数组
        $id_str="";//结果为字符串
        $last_level=$login_level+3;
        $BTwoUserr=$fck->where("id={$id} or (re_path like '%,{$id},%' and re_level<{$last_level})")->order('re_level asc')->select();
        foreach ($BTwoUserr as $item){
            $id_array[]=$item['id'];
            $id_str.=','.$item['id'];
        }
        $id_str=trim($id_str,',');
        //======================================


        $map['uid'] = array('in',$id_array);
        $map['ispay'] = array('gt',0);
		$map['guquan'] = array('neq',1);
		 //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $gouwu->where($map)->count();//总页数
       		$listrows = C('ONE_PAGE_RE');//每页显示的记录数
//            $page_where = 'UserID=' . $UserID;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
//        $where = 'xt_gouwu.ID>0 and xt_gouwu.guquan=0 and xt_gouwu.shu>0 and xt_gouwu.uid ='.$id;
        $where = 'xt_gouwu.ID>0 and xt_gouwu.ispay>0 and xt_gouwu.uid in ('.$id_str.')';
		$field = 'xt_fck.user_id,xt_fck.re_level,xt_fck.nickname,xt_product.name,xt_gouwu.*';
		$join = 'left join xt_fck ON xt_gouwu.UID=xt_fck.id'; //连表查询
		$join1 = 'left join xt_product ON xt_gouwu.DID=xt_product.id'; //连表查询
		$list = $gouwu->where($where)->field($field)->join($join)->join($join1)->order('PDT desc')->page($Page->getPage().','.$listrows)->select();

        $fee_rs=M('fee')->field('s4')->find();
        $s4=$fee_rs['s4'];
        $s4=explode('|',$s4);
        foreach ($list as &$item){
            $item['apart_level']=$item['re_level']-$login_level;
            switch ($item['re_level']-$login_level){
                case 0:
                    $money=$item['money']*$s4[0]*0.01;
                    break;
                case 1:
                    $money=$item['money']*$s4[1]*0.01;
                    break;
                case 2:
                    $money=$item['money']*$s4[2]*0.01;
                    break;
                default:
                    $money=0;
            }
            $item['ticheng']=$money;
        }
		$rs1 = $gouwu->where($map)->sum('Cprice');
		$this->assign('count', $rs1);
		$this->assign('list', $list);
		$this->display('BuycpInfo');
	}
	
	//产品表查询
	public function pro_index(){
		//$this->_Admin_checkUser();
		
			$product = M('product');
			$title = $_REQUEST['stitle'];
			$map = array();
			//if(strlen($title)>0){
				//$map['name'] = array('like','%'. $title .'%');
			//}
			$map['id'] = array('gt',1);
			$orderBy = 'create_time desc,id desc';
			$field  = '*';
	        //=====================分页开始==============================================
	        import ( "@.ORG.ZQPage" );  //导入分页类
	        $count = $product->where($map)->count();//总页数
	   		$listrows = C('ONE_PAGE_RE');//每页显示的记录数
	   		$listrows = 10;//每页显示的记录数
	        $page_where = 'stitle=' . $title ;//分页条件
	        $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
	        //===============(总页数,每页显示记录数,css样式 0-9)
	        $show = $Page->show();//分页变量
	        $this->assign('page',$show);//分页变量输出到模板
	        $list = $product->where($map)->field($field)->order($orderBy)->page($Page->getPage().','.$listrows)->select();
	     
	        $this->assign('list',$list);//数据输出到模板
	        //=================================================
	        $this->display();
//            $xiao=M('xiaof');
//            $all=$xiao->field('id,x1,x2,x3,x4')->select();
//            var_dump($all);
	
	}

	//产品表显示修改
	public function pro_edit(){
		//$this->_Admin_checkUser();
		$EDid = $_GET['EDid'];
		$field = '*';
		$product = M ('product');
		$where = array();
		$where['id'] = $EDid;
		$rs = $product->where($where)->field($field)->find();
		if ($rs){
			$this->assign('rs',$rs);
			$this->us_fckeditor('content',$rs['content'],400,"96%");

            $cptype = M('cptype');
            $list = $cptype->where('status=0 and class=1')->order('id asc')->select();
            $this->assign('list',$list);


            $list2 = $cptype->where('status=0 and class=2')->order('id asc')->select();
            $this->assign('list2',$list2);



			$this->display();
		}else{
			$this->error('没有该信息！');
			exit;
		}
	}

	public function use_upload(){
		$this->display('upload_add');
	}

	//产品表修改保存
	public function pro_edit_save(){
//		$this->_Admin_checkUser();
		$product = M ('product');
		$data = array();
		//h 函数转换成安全html

		$title = trim($_POST['title']);
		$cid = trim($_POST['cid']);
        $money = trim($_POST['money']);
		$a_money = $_POST['a_money'];
//        $b_money = $_POST['b_money'];
        $content = stripslashes($_POST['cp_content']);
        $image = $_POST['image'];//铃声
//        var_dump($image);exit();

		$ctime = trim($_POST['ctime']);
//		$ccname = $_POST['ccname'];
//		$xhname = isset($_POST['xhname'])?1:0;
//		$countid = $_POST['countid'];
		
		$cptype = trim($_POST['cptype']);
		$cptype2 = trim($_POST['cptype2']);
//		$isreg   =  trim($_POST['isreg']);
		$cptype = (int)$cptype;
		$ctime = strtotime($ctime);
		if (empty($title)){
		    echo '标题不能为空!';
			exit;
		}

		if (empty($cptype) || $cptype =="请选择"){
		    echo '一级产品分类不能为空!';
			exit;
		}
		if (empty($cptype2) || $cptype2 =="请选择"){
		    echo '二级产品分类不能为空!';
			exit;
		}
		if (empty($cid)){
            echo '商品编号不能为空!';
			exit;
		}

		if (empty($a_money)||!is_numeric($a_money)){
            echo '成本不能为空!';
            exit;
		}
    if (empty($money)||!is_numeric($money)){
            echo '价格不能为空!';
            exit;
    }
		if($money <= 0){
            echo '输入的价格有误!';
            exit;
		}

		if(!empty($ctime)){
			$data['create_time'] = $ctime;
		}
		$data['cid'] = $cid;
		//$data['ccname'] = $ccname;
		//$data['xhname'] = $xhname;
		$data['money'] = $money;
		$data['a_money'] = $a_money;
		//$data['b_money'] = $b_money;
		$data['name'] = $title;
		$data['content'] = $content;
		$data['cptype'] = $cptype;
		$data['cptype2'] = $cptype2;
		//$data['is_reg'] = $isreg;
        $data['img'] = $image;//铃声
       // $data['ccname'] = $image2;//图片
// 		$data['countid'] = $countid;
		$data['id'] = $_POST['ID'];

		$rs = $product->save($data);
		if (!$rs){
//		    echo M()->_sql();
            echo '编辑失败!';
            exit;
		}else{
            echo '编辑成功!';
            exit;
        }
//		$bUrl = __URL__.'/pro_index';
//		$this->_box(1,'操作成功',$bUrl,1);
//		exit;
	}

	//产品表操作（启用禁用删除）
	public function pro_zz(){
		$this->_Admin_checkUser();
		//处理提交按钮
		$action = $_POST['action'];
		//获取复选框的值
		$PTid = $_POST["checkbox"];
		if ($action=='添加'){

			$cptype = M('cptype');
			$list = $cptype->where('status=0')->order('id asc')->select();
			$this->assign('list',$list);

			$this->us_fckeditor('content',"",400,"96%");

			$this->display('pro');
			exit;
		}
		$product = M ('product');
		switch ($action){
			case '删除';
				$wherea=array();
				$wherea['id'] = array('in',$PTid);
				$rs = $product->where($wherea)->delete();
				   
				if ($rs){
					$bUrl = __URL__.'/pro_index';
					$this->_box(1,'操作成功',$bUrl,1);
					exit;
				}else{
					$bUrl = __URL__.'/pro_index';
					$this->_box(0,'操作失败',$bUrl,1);
				}
				break;
			case '屏蔽产品';
				$wherea=array();
				$wherea['id'] = array('in',$PTid);
				$rs = $product->where($wherea)->setField('yc_cp',1);
				if ($rs){
					$bUrl = __URL__.'/pro_index';
					$this->_box(1,'屏蔽产品成功',$bUrl,1);
					exit;
				}else{
					$bUrl = __URL__.'/pro_index';
					$this->_box(0,'屏蔽产品失败',$bUrl,1);
				}
				break;
			case '解除屏蔽';
				$wherea=array();
				$wherea['id'] = array('in',$PTid);
				$rs = $product->where($wherea)->setField('yc_cp',0);
				if ($rs){
					$bUrl = __URL__.'/pro_index';
					$this->_box(1,'解除屏蔽成功',$bUrl,1);
					exit;
				}else{
					$bUrl = __URL__.'/pro_index';
					$this->_box(0,'解除屏蔽失败',$bUrl,1);
				}
				break;
			default;
				$bUrl = __URL__.'/pro_index';
				$this->_box(0,'操作失败',$bUrl,1);
				break;
		}
	}

	//产品表添加保存
	public function pro_inserts(){
//		$this->_Admin_checkUser();
		$product = M('product');

		$data = array();
		//h 函数转换成安全html
		$content = trim($_POST['cp_content']);
		$title = trim($_POST['title']);
		$cid = trim($_POST['cid']);
		$image = trim($_POST['image']);
		$money = $_POST['money'];
    $a_money = $_POST['a_money'];
        $cptype = $_POST['cptype'];
        $cptype2 = $_POST['cptype2'];
    $is_dz = $_POST['is_dz'];



		if (empty($title)){
			echo '商品名称不能为空!';
			exit;
		}
		if (empty($title)){
			echo '商品编号不能为空!';
			exit;
		}
		if (empty($money)||!is_numeric($money)){
			echo '价格不能为空!';
			exit;
		}
    if (empty($a_money)||!is_numeric($a_money)){
      echo '成本不能为空!';
      exit;
    }
		if (empty($image)){
			echo '请上传产品图片!';
			exit;
		}
		if (empty($cptype) || $cptype == "请选择"){
			echo '请选择一级产品分类!';
			exit;
		}
		if (empty($cptype2) || $cptype2 == "请选择"){
			echo "$cptype2";
			echo '请选择二级产品分类!';
			exit;
		}


		$data['name'] = $title;
		$data['cid'] = $cid;
		$data['content'] = stripslashes($content);
		$data['img'] = $image;
		$data['create_time'] = mktime();
		$data['money'] = $money;
    $data['a_money'] = $a_money;
        $data['cptype'] = $cptype;
        $data['cptype2'] = $cptype2;
    $data['is_dz'] = $is_dz;

//		$data['a_money'] = $a_money;
		//$data['b_money'] = $b_money;
		//$data['ccname'] = $ccname;
		//$data['xhname'] = $xhname;
// 		$data['countid'] = $countid;
//		$data['is_reg'] = $isreg;
		$form_rs = $product->add($data);

		if (!$form_rs){
            echo '添加失败!';
            exit;
		}
        echo '添加成功!';

	}

    /**
     * 添加产品部分
     */
	public function pro_tianjia(){
	    //产品分类
        $cptype = M('cptype');
        $list = $cptype->where('status=0 and class=1')->order('id asc')->select();
        $this->assign('productType',$list);


        $list2 = $cptype->where('status=0 and class=2')->order('id asc')->select();
        $this->assign('list2',$list2);

        $this->display();
    }

    public function find_class_two(){
        $class = $_POST['class'];
        $cptype = M('cptype');
        $class_two = $cptype->where('status=0 and class=2 and shuyu_1='.$class)->order('id asc')->select();  //二级分类返回查询
        return $this->ajaxReturn($class_two);

    }

    public function cptype_index(){
		$this->_Admin_checkUser();
		if ($_SESSION['UrlszUserpass'] == 'MyssGuanChanPin'){
			$product = M('cptype');
			$map = array();
			$map['id'] = array('gt',0);
			$map['class'] = array('eq',1);
			$orderBy = 'id asc';
			$field  = '*';
	        //=====================分页开始==============================================
	        import ( "@.ORG.ZQPage" );  //导入分页类
	        $count = $product->where($map)->count();//总页数
	   		$listrows = 20;//每页显示的记录数
	        $page_where = "" ;//分页条件
	        $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
	        //===============(总页数,每页显示记录数,css样式 0-9)
	        $show = $Page->show();//分页变量
	        $this->assign('page',$show);//分页变量输出到模板
	        $list = $product->where($map)->field($field)->order($orderBy)->page($Page->getPage().','.$listrows)->select();
	        $this->assign('list',$list);//数据输出到模板
	        //=================================================

	        $this->display();
		}else{
            $this->error('错误!');
        }
	}

	public function cptype_edit(){
		$this->_Admin_checkUser();
		$EDid = $_GET['EDid'];
		$field = '*';
		$product = M ('cptype');
		$where = array();
		$where['id'] = $EDid;
		$rs = $product->where($where)->field($field)->find();
		if ($rs){
			$this->assign('rs',$rs);
			$this->display();
		}else{
			$this->error('没有该信息！');
			exit;
		}
	}

	public function cptype_edit_save(){
		$this->_Admin_checkUser();
		$cptype = M ('cptype');
		$title = trim($_POST['title']);
		if (empty($title)){
			$this->error('分类名不能为空!');
			exit;
		}
		$data = array();
        $data['tpname'] = $title;
        $data['status'] = isset($_POST['status'])?1:0;
		$data['id'] = $_POST['id'];
		$rs = $cptype->save($data);
		if (!$rs){
			$this->error('编辑失败！');
			exit;
		}
		$bUrl = __URL__.'/cptype_index';
		$this->_box(1,'操作成功',$bUrl,1);
		exit;
	}

	//处理
	public function cptype_zz(){
		$this->_Admin_checkUser();
		//处理提交按钮
		$action = $_POST['action'];
		//获取复选框的值
		$PTid = $_POST["checkbox"];
		if ($action=='添加'){
			$this->display('cptype_add');
			exit;
		}

        if ($action=='添加二级分类'){
            $this->assign('one_id',$_POST['one_id']);
            $this->display('cptype_add_two');
            exit;
        }
        $product = M ('cptype');
		switch ($action){
			case '删除';
				$wherea=array();
				$wherea['id'] = array('in',$PTid);
				$rs = $product->where($wherea)->delete();
				if ($rs){
					$bUrl = __URL__.'/cptype_index';
					$this->_box(1,'操作成功',$bUrl,1);
					exit;
				}else{
					$bUrl = __URL__.'/cptype_index';
					$this->_box(0,'操作失败',$bUrl,1);
				}
				break;
            case '删除二级分类';
                $wherea=array();
                $wherea['id'] = array('in',$PTid);
                $rs = $product->where($wherea)->delete();
                if ($rs){
                    $bUrl = __URL__.'/cptype_index';
                    $this->_box(1,'操作成功',$bUrl,1);
                    exit;
                }else{
                    $bUrl = __URL__.'/cptype_index';
                    $this->_box(0,'操作失败',$bUrl,1);
                }
                break;
			default;
			$bUrl = __URL__.'/cptype_index';
			$this->_box(0,'操作失败',$bUrl,1);
			break;
		}
	}
    //二级产品分类保存
    public function cptype_inserts_two(){

        $this->_Admin_checkUser();
        $product = M('cptype');
        $title = trim($_POST['title']);
        if (empty($title)){
            $this->error('二级分类名不能为空!');
            exit;
        }
        $data = array();
        $data['tpname'] = $title;
        $data['shuyu_1'] = trim($_POST['one_id']);
        $data['class'] = 2;
        $form_rs = $product->add($data);
        if (!$form_rs){
            $this->error('添加失败');
            exit;
        }
        $bUrl = __URL__.'/cptype_index';
        $this->_box(1,'操作成功',$bUrl,1);
        exit;
    }
	//产品表添加保存
	public function cptype_inserts(){
		$this->_Admin_checkUser();
		$product = M('cptype');
		$title = trim($_POST['title']);
		if (empty($title)){
			$this->error('分类名不能为空!');
			exit;
		}
		$data = array();
		$data['tpname'] = $title;
		$data['class'] = 1;
		$form_rs = $product->add($data);
		if (!$form_rs){
			$this->error('添加失败');
			exit;
		}
		$bUrl = __URL__.'/cptype_index';
		$this->_box(1,'操作成功',$bUrl,1);
		exit;
	}


  public function userLogistics(){
        // $this->_Admin_checkUser();//后台权限检测
        //物流管理
        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
            $shopping = M ('gouwu');
            $product = M('product');
            $UserID = $_REQUEST['UserID'];
            $ss_type = (int) $_REQUEST['type'];
            $map = array();
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                // $map['user_id'] = array('like',"%".$UserID."%");
                $UserID = urlencode($UserID);
            }
            if($ss_type==0){
                $map['ispay'] = array('egt',0);
            }elseif($ss_type==1){
                $map['ispay'] = array('eq',0);
                $map['isfh'] = array('eq',0);
            }elseif($ss_type==2){
                $map['ispay'] = array('eq',0);
                $map['isfh'] = array('eq',1);
            }elseif($ss_type==3){
                $map['ispay'] = array('eq',1);
            }
            $id =  $_SESSION[C('USER_AUTH_KEY')];
            $map['uid'] = $id; 

            $map['lx'] = array('eq',1);
            $map['have_pay'] = array('eq',1);
            //查询字段
            $field   = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $shopping->where($map)->count();//总页数
            $listrows = C('PAGE_LISTROWS')  ;//每页显示的记录数
            $page_where = 'UserID='.$UserID.'&type='.$ss_type;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $shopping ->where($map)->field($field)->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================
            foreach($list as $vv){
                $ttid = $vv['did'];
                $trs = $product->where('id='.$ttid)->find();
                $voo[$ttid] = $trs['name'];
            }
            $this->assign('voo',$voo);
            $title = '物流管理';
            $this->assign('title',$title);

            if(empty($ss_type)){
              $ss_type = 0;
            }
            $_SESSION['ss_type'] = $ss_type;

            $this->display();
        }else{
            $this->error('错误!');
            exit;
        }
    }


    public function adminLogistics(){
        $this->_Admin_checkUser();//后台权限检测
        //物流管理
        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
            $shopping = M ('gouwu');
            $product = M('product');
            $UserID = $_REQUEST['UserID'];
            $ss_type = (int) $_REQUEST['type'];
            $map = array();
            if (!empty($UserID)){
                import ( "@.ORG.KuoZhan" );  //导入扩展类
                $KuoZhan = new KuoZhan();
                if ($KuoZhan->is_utf8($UserID) == false){
                    $UserID = iconv('GB2312','UTF-8',$UserID);
                }
                unset($KuoZhan);
                // $map['user_id'] = array('like',"%".$UserID."%");
                $UserID = urlencode($UserID);
            }
            if($ss_type==0){
                $map['ispay'] = array('egt',0);
            }elseif($ss_type==1){
                $map['ispay'] = array('eq',0);
                $map['isfh'] = array('eq',0);
            }elseif($ss_type==2){
                $map['ispay'] = array('eq',0);
                $map['isfh'] = array('eq',1);
            }elseif($ss_type==3){
                $map['ispay'] = array('eq',1);
            }
            $map['lx'] = array('eq',1);
            $map['have_pay'] = array('eq',1);
            //查询字段
            $field   = '*';
            //=====================分页开始==============================================
            import ( "@.ORG.ZQPage" );  //导入分页类
            $count = $shopping->where($map)->count();//总页数
            $listrows = C('PAGE_LISTROWS')  ;//每页显示的记录数
            $page_where = 'UserID='.$UserID.'&type='.$ss_type;//分页条件
            $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
            //===============(总页数,每页显示记录数,css样式 0-9)
            $show = $Page->show();//分页变量
            $this->assign('page',$show);//分页变量输出到模板
            $list = $shopping ->where($map)->field($field)->page($Page->getPage().','.$listrows)->select();
            $this->assign('list',$list);//数据输出到模板
            //=================================================
            foreach($list as $vv){
                $ttid = $vv['did'];
                $trs = $product->where('id='.$ttid)->find();
                $voo[$ttid] = $trs['name'];
            }
            $this->assign('voo',$voo);
            $title = '物流管理';
            $this->assign('title',$title);

            if(empty($ss_type)){
              $ss_type = 0;
            }
            $_SESSION['ss_type'] = $ss_type;

            $this->display();
        }else{
            $this->error('错误!');
            exit;
        }
    }

    public function adminLogisticsAC(){
        //处理提交按钮
        $action = $_POST['action'];
        //获取复选框的值
        $XGid = $_POST['tabledb'];
        if (!isset($XGid) || empty($XGid)){
            $bUrl = __URL__.'/adminLogistics';
            $this->_box(0,'请选择货物！',$bUrl,1);
            exit;
        }
        switch ($action){
            case '确认发货';
                $this->_adminLogisticsOK($XGid);
                break;
            case '确定收货';
                $this->_adminLogisticsDone($XGid);
                break;
            case '删除';
                $this->_adminLogisticsDel($XGid);
                break;
            default;
                $bUrl = __URL__.'/adminLogistics';
                $this->_box(0,'没有该货物！',$bUrl,1);
                break;
        }
    }

    private function _adminLogisticsOK($XGid){
        //确定发货
        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
            $shopping = M ('gouwu');
            $where = array();
            $where['id'] = array ('in',$XGid);
            $where['isfh'] = array ('eq',0);

            $valuearray = array(
                'isfh' => '1',
                'fhdt' => mktime()
            );
            $shopping->where($where)->setField($valuearray);
            unset($shopping,$where);

            $bUrl = __URL__.'/adminLogistics';
            $this->_box(1,'发货成功！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
        }
    }

    private function _adminLogisticsDone($XGid){
        //确定发货
        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
            $shopping = M ('gouwu');

            $where1 = array();
            $where1['id'] = array ('in',$XGid);
            $where1['isfh'] = array ('eq',0);

            $where = array();
            $where['id'] = array ('in',$XGid);
            $where['ispay'] = array ('eq',0);



            $valuearray1 = array(
                'isfh' => '1',
                'fhdt' => mktime()
            );

            $valuearray = array(
                'ispay' => '1',
                'okdt' => mktime()
            );

            $shopping->where($where1)->setField($valuearray1);
            $shopping->where($where)->setField($valuearray);
            unset($shopping,$where1,$where);

            $bUrl = __URL__.'/adminLogistics';
            $this->_box(1,'确认收货成功！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
            exit;
        }
    }

    private function _adminLogisticsDel($XGid){
        //确定发货
        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
            $shopping = M ('gouwu');
            $where = array();
            $where['id'] = array ('in',$XGid);
            $shopping->where($where)->delete();
            unset($shopping,$where);

            $bUrl = __URL__.'/adminLogistics';
            $this->_box(1,'删除成功！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
        }
    }

//    public function adminLogisticsAC(){
//        //处理提交按钮
//        $action = $_POST['action'];
//        //获取复选框的值
//        $XGid = $_POST['tabledb'];
//        if (!isset($XGid) || empty($XGid)){
//            $bUrl = __URL__.'/adminLogistics';
//            $this->_box(0,'请选择货物！',$bUrl,1);
//            exit;
//        }
//        switch ($action){
//            case '确认处理';
//                $this->_adminLogisticsOK($XGid);
//                break;
//            case '确认支付';
//                $this->_adminLogisticsPay($XGid);
//                break;
//            case '已退订';
//                $this->_adminLogisticsRuturn($XGid);
//                break;
//            case '通道问题';
//                $this->_adminLogisticsNone($XGid);
//                break;
//
//            case '确定收货';
//                $this->_adminLogisticsDone($XGid);
//                break;
//            case '删除';
//                $this->_adminLogisticsDel($XGid);
//                break;
//	        default;
//	            $bUrl = __URL__.'/adminLogistics';
//	            $this->_box(0,'没有该货物！',$bUrl,1);
//	            break;
//        }
//    }
    //已经处理
//    private function _adminLogisticsOK($XGid){
//    	//确定发货
//        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
//            $fck=M('fck');
//            $shopping = M ('gouwu');
//            $where = array();
//            $where['id'] = array ('in',$XGid);
//            $where['isfh'] = array ('eq',0);
//
//            $valuearray = array(
//            	'isfh' => '1',
//                'ispay'=>'1',
//                'fhdt' => mktime(),
//            	'okdt' => mktime()
//            );
//
////            $result=$shopping->where($where)->setField($valuearray);
//            $result=$shopping->where($where)->select();
//            foreach ($result as $vo){
//                //这个单
//                $tmp=$shopping->where(array('id'=>$vo['id']))->setField($valuearray);
//                //这个人
//                $thisUser=$fck->where(array('id'=>$vo['uid']))->find();
//
//                if($tmp){
//                    $fee_rs=M('fee')->field('s4')->find();
//                    $s4=$fee_rs['s4'];
//                    $s4=explode('|',$s4);
//                    $three_users=$fck->where("id={$thisUser['id']} or id in (0{$thisUser['re_path']}0)")->order('re_level desc')->limit(3)->select();
//                    $pay=0;//后台支付了多少钱
//                    foreach ($three_users as $three_user){
//                        $apart=$thisUser['re_level']-$three_user['re_level'];
//                        switch ($apart){
//                            case 0:
//                                $money=$vo['money']*$s4[0]*0.01;
//                                break;
//                            case 1:
//                                $money=$vo['money']*$s4[1]*0.01;
//                                break;
//                            case 2:
//                                $money=$vo['money']*$s4[2]*0.01;
//                                break;
//                            default:
//                                $money=0;
//                        }
//                        //是管理员就不算提成，后面直接加上这个单的总金额
//                        if($three_user['id']==1){
//                            $money=0;
//                        }
//                        //agent_use为剩余提现，b1为销售收益，kt为合作收益
//                        $fck->execute("update __TABLE__ set agent_use=agent_use+{$money},b1=b1+{$money} where id={$three_user['id']}");
//                        if($apart>0){
//                            $fck->execute("update __TABLE__ set agent_kt=agent_kt+{$money} where id={$three_user['id']}");
//                        }
//                        $pay+=$money;
//                    }
//                    //是管理员直接加上这个单的利润
//                    $money_total=$vo['money']-$pay;
//                    $fck->execute("update __TABLE__ set agent_use=agent_use+{$money_total},b1=b1+{$money_total} where id=1");
//                }
//            }
//            unset($shopping,$where);
//
//            $bUrl = __URL__.'/adminLogistics';
//            $this->_box(1,'处理成功！',$bUrl,1);
//            exit;
//        }else{
//            $this->error('错误!');
//        }
//    }
    //已经支付成功
    private function _adminLogisticsPay($XGid){
        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
            $gouwu=M('gouwu');
            $XGid='201611121313142904A';
            $dingdan=$gouwu->where(array('ccxhbz'=>$XGid,is_pay=>0))->find();

            if($dingdan){
                $fck=M('fck');
                $valuearray = array(
                    'ispay'=>'1',
                    'okdt' => mktime()
                );
                //处理这个单
                $tmp=$gouwu->where(array('id'=>$dingdan['id']))->setField($valuearray);
                //这个人
                $thisUser=$fck->where(array('id'=>$dingdan['uid']))->find();
                $fee_rs=M('fee')->field('s4')->find();
                $s4=$fee_rs['s4'];
                $s4=explode('|',$s4);
                $three_users=$fck->where("id={$dingdan['uid']} or id in (0{$thisUser['re_path']}0)")->order('re_level desc')->limit(3)->select();
                $pay=0;//后台支付了多少钱
                foreach ($three_users as $three_user){
                    $apart=$thisUser['re_level']-$three_user['re_level'];
                    switch ($apart){
                        case 0:
                            $money=$dingdan['money']*$s4[0]*0.01;
                            break;
                        case 1:
                            $money=$dingdan['money']*$s4[1]*0.01;
                            break;
                        case 2:
                            $money=$dingdan['money']*$s4[2]*0.01;
                            break;
                        default:
                            $money=0;
                    }

                    if($three_user['id']==1){
//                        $money=$dingdan['money'];
                        $money=0;
                    }
                    //agent_cf为剩余提现，b1为销售收益
                    $fck->execute("update __TABLE__ set agent_cf=agent_cf+{$money} where id={$three_user['id']}");
                    $pay+=$money;
                }
                //是管理员直接加上这个单的利润
                $money_total=$dingdan['money']-$pay;
                $fck->execute("update __TABLE__ set agent_cf=agent_cf+{$money_total} where id=1");
                unset($shopping,$where);

            $bUrl = __URL__.'/adminLogistics';
            $this->_box(1,'处理成功！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
        }
    }
    }
    //已退订
    private function _adminLogisticsRuturn($XGid){
        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
            $fck=M('fck');
            $shopping = M ('gouwu');
            $where = array();
            $where['id'] = array ('in',$XGid);
            $where['isfh'] = array ('neq',2);

            $valuearray = array(
                'isfh'=>'2',
                'fhdt' => mktime()
            );

            $result=$shopping->where($where)->setField($valuearray);

            unset($shopping,$where);

            $bUrl = __URL__.'/adminLogistics';
            $this->_box(1,'处理成功！',$bUrl,1);
            exit;
        }else{
            $this->error('错误!');
        }
    }
    //通道问题
//    private function _adminLogisticsNone($XGid){
//        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
//            $fck=M('fck');
//            $shopping = M ('gouwu');
//            $where = array();
//            $where['id'] = array ('in',$XGid);
//            $where['isfh'] = array ('neq',3);
//
//            $valuearray = array(
//                'isfh'=>'3',
//                'fhdt' => mktime()
//            );
//
//            $result=$shopping->where($where)->setField($valuearray);
//
//            unset($shopping,$where);
//
//            $bUrl = __URL__.'/adminLogistics';
//            $this->_box(1,'处理成功！',$bUrl,1);
//            exit;
//        }else{
//            $this->error('错误!');
//        }
//    }
//
//
//    private function _adminLogisticsDone($XGid){
//    	//确定发货
//        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
//            $shopping = M ('gouwu');
//
//            $where1 = array();
//			$where1['id'] = array ('in',$XGid);
//            $where1['isfh'] = array ('eq',0);
//
//            $where = array();
//            $where['id'] = array ('in',$XGid);
//            $where['ispay'] = array ('eq',0);
//
//
//
//            $valuearray1 = array(
//            	'isfh' => '1',
//            	'fhdt' => mktime()
//            );
//
//            $valuearray = array(
//            	'ispay' => '1',
//            	'okdt' => mktime()
//            );
//
//            $shopping->where($where1)->setField($valuearray1);
//            $shopping->where($where)->setField($valuearray);
//            unset($shopping,$where1,$where);
//
//            $bUrl = __URL__.'/adminLogistics';
//            $this->_box(1,'确认收货成功！',$bUrl,1);
//            exit;
//        }else{
//            $this->error('错误!');
//            exit;
//        }
//    }
//
//    private function _adminLogisticsDel($XGid){
//    	//确定发货
//        if ($_SESSION['UrlszUserpass'] == 'MyssWuliuList'){
//            $shopping = M ('gouwu');
//            $where = array();
//            $where['id'] = array ('in',$XGid);
//            $shopping->where($where)->delete();
//            unset($shopping,$where);
//
//            $bUrl = __URL__.'/adminLogistics';
//            $this->_box(1,'删除成功！',$bUrl,1);
//            exit;
//        }else{
//            $this->error('错误!');
//        }
//    }

    
    /**
     * 上传图片
     * **/
	public function upload_fengcai_pp() {
		$this->_Admin_checkUser();//后台权限检测
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $this->_upload_fengcai_pp();
        }
    }

    protected function _upload_fengcai_pp()
    {
        header("content-type:text/html;charset=utf-8");
        $this->_Admin_checkUser();//后台权限检测
        // 文件上传处理函数

        //载入文件上传类
        import("@.ORG.UploadFile");
        $upload = new UploadFile();

        //设置上传文件大小
        $upload->maxSize  = 1048576 * 2 ;// TODO 50M   3M 3292200 1M 1048576

        //设置上传文件类型
        $upload->allowExts  = explode(',','jpg,gif,png,jpeg,mp3');

        //设置附件上传目录
        $upload->savePath =  './Public/Uploads/image/shop/';

        //设置需要生成缩略图，仅对图像文件有效
       $upload->thumb =  false;

       //设置需要生成缩略图的文件前缀
        $upload->thumbPrefix   =  'm_';  //生产2张缩略图

       //设置缩略图最大宽度
        $upload->thumbMaxWidth =  '800';

       //设置缩略图最大高度
        $upload->thumbMaxHeight = '600';

       //设置上传文件规则
//		$upload->saveRule = uniqid;
		$upload->saveRule = date("Y").date("m").date("d").date("H").date("i").date("s").rand(1,100);

       //删除原图
       $upload->thumbRemoveOrigin = true;

        if(!$upload->upload()) {
            //捕获上传异常
            $error_p=$upload->getErrorMsg();
            echo "<script>alert('".$error_p."');history.back();</script>";
        }else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $U_path=$uploadList[0]['savepath'];
            $U_nname=$uploadList[0]['savename'];
            $U_inpath=(str_replace('./Public/','__PUBLIC__/',$U_path)).$U_nname;
           // return $this->ajaxReturn({"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": '.$id.'}}});
            //echo "<script>window.parent.form1.image.value='".$U_inpath."';</script>";
           // echo "<span style='font-size:12px;'>上传完成！</span>";
            exit;

        }
    }

    /**
     * 上传图片
     * **/
    public function upload_fengcai_pp_2() {
        // $this->_Admin_checkUser();//后台权限检测
        
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $this->_upload_fengcai_pp_2();
        }
    }

    protected function _upload_fengcai_pp_2()
    {
        header("content-type:text/html;charset=utf-8");
        // $this->_Admin_checkUser();//后台权限检测
        // 文件上传处理函数

        //载入文件上传类
        import("@.ORG.UploadFile");
        $upload = new UploadFile();

        //设置上传文件大小
        $upload->maxSize  = 1048576 * 2 ;// TODO 50M   3M 3292200 1M 1048576

        //设置上传文件类型
        $upload->allowExts  = explode(',','jpg,gif,png,jpeg,mp3');

        //设置附件上传目录
        $upload->savePath =  './Public/Uploads/image/shop/';

        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb =  false;

        //设置需要生成缩略图的文件前缀
        $upload->thumbPrefix   =  'm_';  //生产2张缩略图

        //设置缩略图最大宽度
        $upload->thumbMaxWidth =  '133';

        //设置缩略图最大高度
        $upload->thumbMaxHeight = '133';

        //设置上传文件规则
//		$upload->saveRule = uniqid;
        $upload->saveRule = date("Y").date("m").date("d").date("H").date("i").date("s").rand(1,100);

        //删除原图
        $upload->thumbRemoveOrigin = true;

        if(!$upload->upload()) {
            //捕获上传异常
            $error_p=$upload->getErrorMsg();
             echo "<script>alert('".$error_p."');history.back();</script>";
//            return $this->ajaxReturn($error_p);
        }else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $U_path=$uploadList[0]['savepath'];
            $U_nname=$uploadList[0]['savename'];
            $U_inpath=(str_replace('./Public/','__PUBLIC__/',$U_path)).$U_nname;

             echo "<script>window.parent.form1.image.value='".$U_inpath."';</script>";
             echo "<span style='font-size:12px;'>上传完成！</span>";
             exit;
//            return $this->ajaxReturn(array('status'=>1,'info'=>'上传完成！','url'=>$U_inpath));
        }
    }


    //二级分类
    public function look_two(){
        $product = M('cptype');
        $map = array();
        $map['id'] = array('gt',0);
        $map['shuyu_1'] = array('eq',$_GET['id']);
        $map['class'] = array('eq',2);
        $orderBy = 'id asc';
        $field  = '*';
        //=====================分页开始==============================================
        import ( "@.ORG.ZQPage" );  //导入分页类
        $count = $product->where($map)->count();//总页数
        $listrows = 20;//每页显示的记录数
        $page_where = "" ;//分页条件
        $Page = new ZQPage($count, $listrows, 1, 0, 3, $page_where);
        //===============(总页数,每页显示记录数,css样式 0-9)
        $show = $Page->show();//分页变量
        $this->assign('page',$show);//分页变量输出到模板
        $list = $product->where($map)->field($field)->order($orderBy)->page($Page->getPage().','.$listrows)->select();
        $this->assign('list',$list);//数据输出到模板
        //=================================================
        $this->assign('id',$_GET['id']);

        $yiji = $product->where('id='.$_GET['id'])->getField('tpname');
        $this->assign('tpname',$yiji);

        $this->display();
    }


    //导出物流表格
    public function wuliu(){
        //导出excel
        set_time_limit(0);

        header("Content-Type:   application/vnd.ms-excel");
        header("Content-Disposition:   attachment;   filename=Transport.xls");
        header("Pragma:   no-cache");
        header("Content-Type:text/html; charset=utf-8");
        header("Expires:   0");



        $gouwu = M ('gouwu');  //奖金表
        $product = M ('product');  //奖金表

        $map = array();
        $ss_type = $_SESSION['ss_type'];
        if($ss_type==0){
                $map['ispay'] = array('egt',0);
            }elseif($ss_type==1){
                $map['ispay'] = array('eq',0);
                $map['isfh'] = array('eq',0);
            }elseif($ss_type==2){
                $map['ispay'] = array('eq',0);
                $map['isfh'] = array('eq',1);
            }elseif($ss_type==3){
                $map['ispay'] = array('eq',1);
            }
        $map['jihuo'] = array('eq',0);
        $map['lx'] = array('eq',1);
        $map['have_pay'] = array('eq',1);
        $field   = '*';
        $list = $gouwu->where($map)->field($field)->order('pdt asc')->select();
        $title   =   "商品物流管理 导出时间:".date("Y-m-d   H:i:s");

        echo   '<table   border="1"   cellspacing="2"   cellpadding="2"   width="50%"   align="center">';
        //   输出标题
        echo   '<tr   bgcolor="#cccccc"><td   colspan="10"   align="center">'   .   $title   .   '</td></tr>';
        //   输出字段名
        echo   '<tr  align=center>';
        echo   "<td>序号</td>";
        echo   "<td>购货时间</td>";
        echo   "<td>支付时间</td>";
        echo   "<td>发货时间</td>";
        echo   "<td>会员编号</td>";
        echo   "<td>收货人</td>";
        echo   "<td>收货地址</td>";
        echo   "<td>电话</td>";
        echo   "<td>产品名称</td>";
        echo   "<td>数量</td>";
        echo   "<td>总价</td>";
        echo   "<td>状态</td>";
        echo   '</tr>';


        $i = 0;
        foreach($list as $row)   {
            $i++;
            $num = strlen($i);
            if ($num == 1){
                $num = '000'.$i;
            }elseif ($num == 2){
                $num = '00'.$i;
            }elseif ($num == 3){
                $num = '0'.$i;
            }else{
                $num = $i;
            }
            if ($row['fhdt'] >0){
                $fhdt = date("Y-m-d H:i:s",$row['fhdt']);
            }else{
                $fhdt = "未发货";
            }

            if ($row['have_pay'] ==1){
                $have_pay = date("Y-m-d H:i:s",$row['have_pay_time']);
            }else{
                $have_pay = "未支付";
            }

            $ttid = $row['did'];
            $trs = $product->where('id='.$ttid)->find();
            $voo[$ttid] = $trs['name'];

            if ($row['ispay'] ==1 ){
                $status = "已确认收货";
            }else{
                if ($row['isfh'] ==0){
                    $status = "未发货";
                }
                if ($row['isfh'] ==1){
                    $status = "已发货";
                }

            }


            echo   '<tr align=center>';
            echo   '<td>'   .  chr(28).$num   .   '</td>';
            echo   "<td>"   .  date("Y-m-d H:i:s",$row['pdt']).  "</td>";
            echo   "<td>"   .  $have_pay.  "</td>";
            echo   "<td>"   .  $fhdt.  "</td>";
            echo   "<td>"   .   $row['user_id'].  "</td>";
            echo   "<td>"   .   $row['us_name'].  "</td>";
            echo   "<td>"   .   $row['us_address'].  "&nbsp;</td>";
            echo   "<td>"   .   $row['us_tel'].  "&nbsp;</td>";
            echo   "<td>"   .  $voo[$row['did']].  "&nbsp;</td>";
            echo   "<td>"   .  $row['shu'].  "&nbsp;</td>";
            echo   "<td>"   .  $row['cprice'].  "&nbsp;</td>";
            echo   "<td>"   .  $status.  "&nbsp;</td>";
            echo   '</tr>';
        }
        echo   '</table>';
    }
}
?>